我在app.js
中有这样的课程function Player(elem, options){
this.events = []; // Queue of events
new Plugin(elem, options, this);
}
Player.prototype = {
init : function(){
},
on : function(event,callback) {
this.events.push(event.toLowerCase(), callback);
},
fire : function(){
}
};
function Plugin(elem, options, Player){
// How can i execute in this class the event event-play like
Player.events[1].apply(this,args.slice(1)); // here is the problem
}
我在index.html中有一个这样的类我有这个
api = new Player("video",{});
api.on('event-play',function(event,data){
console.log(event);
});
我正在设置Player类,并注册事件'event-play'并附加回调,但在Plugin类中我无法执行该事件,因为索引1不存在。 (Player.events [1])但我在on方法中附加。 我怎么能这样做?