2012-05-11 12 views

答えて

3

lang.hitch(scope, method)、すなわち、それは所与scopeで機能methodを呼び出す機能を返し、クロージャを返します。それはあなたが書くことができるように、オブジェクト指向のコードにコールバックを定義する場合は特に便利です:

on(dom.byId("button"), "click", lang.hitch(this, "callback")); 

の代わり:

on(dom.byId("button"), "click", function(scope, method) { 
    return function() { 
     method.apply(scope); 
    } 
}(this, this["callback"])); // execute the anonymous function immediately to get a closure 

このような何かが動作します:

on(dom.byId("button"), "click", this["callback"]); 

が、this内部をcallbackメソッドはbuttonを指します。

詳細については、jsFiddleでhttp://jsfiddle.net/phusick/r7jLr/

+0

thx – jbduzan