6 回答

TA貢獻1934條經(jīng)驗 獲得超2個贊
鉤子函數(shù) 在不同的時候調(diào)不同的方法 傳不同的值啊 類似
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條經(jīng)驗 獲得超7個贊
這個。。函數(shù)參數(shù)你想起什么名字起什么名字,名字一樣不代表值就一樣,值只跟調(diào)用函數(shù)傳入有關(guān),參數(shù)名只是別名
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
回調(diào)函數(shù)
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條經(jīng)驗 獲得超5個贊
添加回答
舉報