0

私はこの小さなスクリプトがあります。Javascript Mootoolsイベントと彼の呼び出し元をクリックしますか?

var moolang = new Class({ 
    initialize: function(element) { 

     this.el = $(element); 
     this.el.addEvent('click', this.popup); 

    }, 

    popup: function() 
    { 
     //this.id = the id of the element. 
    } 
}); 

を、私はポップアップ機能で「これを」知りたいです。しかし、私は警告(this.el.id)のようなものを試してみると、this.el:/

イベントがどのクラスを追加するのか知る方法はありますか?

答えて

5

着信音が適切なコンテキストを持つように添付イベントを変更します。それ以外の場合は、イベントリスナーのコンテキストがターゲット要素になります。

// Change this line 
this.el.addEvent('click', this.popup); 
//To this 
this.el.addEvent('click', this.popup.bind(this)); // popup->this == this 

jsfiddle here MooToolsのdocumentationを参照してください。関数のコンテキストをバインドする。

関連する問題