【发布时间】:2011-12-14 23:55:01
【问题描述】:
通常,当在 setInterval 中引用“this”时,我会指定一个替代的“self”引用。是否有可能在原型方法的上下文中完成类似的事情?以下代码错误。
function Foo() {}
Foo.prototype = {
bar: function () {
this.baz();
},
baz: function () {
this.draw();
requestAnimFrame(this.baz);
}
};
【问题讨论】:
标签: javascript scope lexical-scope