这是闭包内的循环引用吗?
Is this a circular reference inside the closure?
我想知道 self
是否会因被 add
捕获而导致循环引用。这对旧浏览器的垃圾收集器来说会是个问题吗?
var fun = function() {
var self = this;
this.value = 0;
this.add = function(number) {
self.value += number;
};
};
fun.prototype.inc = function() {
this.value++;
};
fun.prototype.dec = function() {
this.value--;
};
I was wondering if self
cause a circular reference by being captured by add
.
是的。
And will this be a problem for a garbage collector of an old browser.
没有。甚至不是一个古老的。
我想知道 self
是否会因被 add
捕获而导致循环引用。这对旧浏览器的垃圾收集器来说会是个问题吗?
var fun = function() {
var self = this;
this.value = 0;
this.add = function(number) {
self.value += number;
};
};
fun.prototype.inc = function() {
this.value++;
};
fun.prototype.dec = function() {
this.value--;
};
I was wondering if
self
cause a circular reference by being captured byadd
.
是的。
And will this be a problem for a garbage collector of an old browser.
没有。甚至不是一个古老的。