Javascript稍后回调

Javascript稍后回调,javascript,jquery,callback,Javascript,Jquery,Callback,我在app.js中有这样一个类 function Player(elem, options){ this.events = []; // Queue of events new Plugin(elem, options, this); } Player.prototype = { init : function(){ }, on : function(

我在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”并附加回调,但在插件类中我无法执行该事件,因为索引1不存在。(Player.events[1])但我附加了on方法。
我该怎么做呢?

好吧,创建实例时,您正在调用
插件。此时回调还不存在。您没有解释代码的用途,因此我无法提供解决方案的建议。目的是在插件类中触发事件“事件播放”。下面是JSFIDLE中的示例,但您希望何时触发事件?现在,当您调用
插件时触发它。是的,我想在调用插件构造函数时触发事件。