6 回答

TA貢獻1934條經驗 獲得超2個贊
鉤子函數 在不同的時候調不同的方法 傳不同的值啊 類似
function test(obj){
if(obj.before){
obj.before({a:1});
}
setTimeout(obj.after || Function.prototype,1000,{c:2})
}
test({
before:function(obj){
console.log(obj);
},
after:function(obj){
console.log(obj);
}
})

TA貢獻1852條經驗 獲得超7個贊
這個。。函數參數你想起什么名字起什么名字,名字一樣不代表值就一樣,值只跟調用函數傳入有關,參數名只是別名
function test(a){console.log(a)}
test(1);//1
function test(b){console.log(b)}
test(1);//1
function test(a){console.log(a)}
test(2);//2
回調函數
function test(options){
option.beofreSetTimeout(3,2,1);
setTimeout(function(){
option.callback(1,2,3)
},1000)
}
test({
beofreSetTimeout:function(e,b,r){
console.log(e,b,r);//3,2,1
},
callback:function(e,b,r){
console.log(e,b,r);//1,2,3
}
})

TA貢獻1876條經驗 獲得超5個贊
添加回答
舉報