【发布时间】:2012-05-26 23:50:42
【问题描述】:
我使用 this 多次引用 JavaScript 对象的地方
var myObj = {
method1 : function() {},
method2 : function() {},
method3 : function {},
init : function() {
this.method1();
this.method2();
this.method3();
}
};
是否有任何性能提升,我应该将this 存储在变量中吗?喜欢:
init : function() {
var self = this;
self.method1();
self.method2();
self.method3();
}
【问题讨论】:
-
你明显误解了
self的用法。 -
+1 表示写得很好的问题。
标签: javascript oop variables this