我需要在2个事件上调用一个函数。
On first event, f1() is called.
On second event, f1(), f2() are called.
是否可以在第二个事件中调用f1()而不提及f1()(使用第一个事件)?
最佳答案
是!如果在触发“第一个事件”时调用f1()
,只需确保在响应“第二个事件”时就触发“第一个事件”。
我想可能会有一些变化:
var firstEvent = function() {
f1();
}
var secondEvent = function() {
f2();
firstEvent();
}
要么
this.on('firstEvent', function() {
f1();
});
this.on('secondEvent', (function() {
f2();
this.trigger('firstEvent');
}).bind(this));
关于javascript - 我们可以在另一个事件上调用为一个事件编写的JS函数吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41218024/