![](/img/trans.png)
[英]How argument is being passed in the function(which itself is an argument) in JavaScript
[英]How can we pass argument to function which itself is passed as argument in javascript
function fun (a, b) {
console.log(a + ' ' + b);
return a == b;
}
function test(condition) {
for(let i = 0; i < 1; i++) {
if(condition()){
break;
}
}
}
我們如何將 function fun 作為參數傳遞給 function 測試中的參數 a 和 b(a 和 b 是可變的)。 寫作test(fun('a', 'b'));
導致錯誤。
您可以使用這樣的closure
:
test(function(){ return fun('a', 'b'); });
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.