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个赞
添加回答
举报