1
我想分配setInterval()
通過此鏈接pass <or> operator into function as parameter?傳遞運營商對setInterval()動作
以下LiraNuna
function actualFunction(passedValue:Number, compareFunction:Function) {
/* ... */
if(compareFunction(passedValue, staticValue)) {
/* ... Do something ... */
}
/* ... */
}
actualFunction(6, function(x:Number, y:Number) {
return x > y;
});
的答案傳遞一個操作員的說法,但我似乎並沒有做知道該怎麼做,因爲在啓動setInterva()
時只調用函數名稱。
典型的啓動:
function actualFunction(passedValue:Number, compareFunction:Function) {
/* ... */
if(compareFunction(passedValue, staticValue)) {
/* ... Do something ... */
}
/* ... */
}
setInterval(actualFunction,10)
現在,我想分配
actualFunction(6, function(x:Number, y:Number) {
return x > y;
});
內
setInterval()
,我會怎麼做呢?
我們如何包含'return x> y',因爲在其他情況下,我們也會用'return x
我編輯了我的答案,請測試並查看它是否有效。嘗試創建單獨的方法進行比較,如果要多次調用此代碼,請不要將它們作爲行方法傳遞。 –
我得到了整個代碼的工作,但它需要兩個函數,只有區別是x> y和x