誰かが 'unless'関数の役割と 'test'と 'then'の引数をどのように説明できますか?JavaScript関数を他の関数に渡す
function unless(test, then) {
if (!test) then();
}
function repeat(times, body) {
for (var i = 0; i < times; i++) body(i);
}
repeat(3, function(n) {
unless(n % 2, function() {
console.log(n, "is even");
});
});
// ▹ 0 is even
// ▹ 2 is even
あなたがそれに渡されたものを引数見ることができ、それは本体のみの1行を持っています。あなたは何を理解していますか? – Quentin
複数の場合に使用できます。 – Rajesh
ありがとうございました。この行は私をスローします。if(n%2 === 0){console.log(n、 "偶数")} !test)then();テストがfalseであれば、これは言うのですか? – stckpete