Nir*_*Nir 3 javascript mootools
如果你可以向我解释为什么shout()不断被调用,我会很高兴,尽管它应该"消失".
var myclass = new Class({
myid: "greatidea",
initialize: function(element) {
var shout = function() { alert(this.myid); };
shout.periodical(5000, this); // test debug
}
Run Code Online (Sandbox Code Playgroud)
});
x = new myclass ();
alert(x);
x=null;
alert(x);
另见http://mootools.net/shell/jhCBz/
基本上,我明白了这个想法:函数有自己的注册,现在独立于调用它的对象.但我很乐意得到一个真正的解释.
谢谢.
功能始终是独立的.只要有对函数的引用,它就会继续存在.在这种情况下,您的对象也是如此,因为您已经this将对它的引用(via )传递给periodical()函数,该函数将其保留在上下文中.
| 归档时间: |
|
| 查看次数: |
222 次 |
| 最近记录: |