我有一个自定义对象,它实现了稍后将执行的功能。有人会这样称呼它:
customObject.onSomething(function(e) {
// do something with e
console.log('foobar');
});
以下是 onSomething 的创建方式:
var CustomObject = function() {
this.onSomething = function(callback) {
// If the user passes in parameter(s), how can I modify them before calling?
callback.apply(this);
}
}
如何在对函数执行应用或调用之前修改用户传入的参数?