问题是如何使用不同的参数再次执行该函数。
// my class
let x = new class CB {
constructor() {
this.onEnter = function(callback) {
this.user = { user: 'Peter', isMember: true };
callback(this.user);
}
}
}
//my call
x.onEnter(function(user) {
console.log(user.user + " listed!");
});
// How to do a second call....how with different parameters every time?
console.log(x.onEnter);
...
与您第一次使用相同的方法。您只需传递其他功能即可。
x.onEnter(function(user) {
console.log(user.user + " listed!");
});
x.onEnter(function(user) {
console.log(user.user + " twisted!");
});