Suggested Q: Memory implications of using closure methods vs prototype methods
mastef opened this issue · comments
Which of these is more memory efficient, and why?
function ProtoPerson() {}
ProtoPerson.prototype.getName = function() {
return "MyName";
};
ProtoPerson.prototype.getLink = function() {
return "http://mycompany.com/myLinks/" + this.getName();
};
var protoPersons = [];
for (var i = 0; i < 100000; i++) {
protoPersons.push(new ProtoPerson);
}
function ClosurePerson() {
this.getName = function() {
return "MyName";
};
this.getLink = function() {
return "http://mycompany.com/myLinks/" + this.getName();
};
}
var closurePersons = [];
for (var i = 0; i < 100000; i++) {
closurePersons.push(new ClosurePerson);
}
This should just be a PR, although from an editorial perspective, this particular sort of question doesn't fit with what we normally do.