Suppose I write a class A in my Jetpack-based library (i.e. we are talking about chrome / extension code) :
function A() {
}
A.prototype = {
};
The user creates an instance of the class A:
var a = new A();
Now suppose I want to track all the instances Athat were created, I could do:
var listA = [];
and add listA.push(this);to the constructor A, as a result we get:
var listA = [];
function A() {
listA.push(this);
}
A.prototype = {
};
, A (, A ). : listA A, . , listA A, . .
listA . , -, , . - :
var weak_a = new weakRef(a);
assert(weak_a.ref === a);
, , , . listA. ?