It all depends on how you use it.
Using the Tomas function, you actually save the Sum for an EACH object that you attach too.
If you save the function somewhere else before inserting into your object, you will use less memory.
The bad:
var array = [];
for (i=0; i<100000; i++)
array[i] = { test: function(){ "A pretty long string" }; }
Good:
var array = [],
long = function(){ "A pretty long string"; };
for (i=0; i<100000; i++)
array[i] = { test: long }
~ 3mb , ~ 20mb . , 100000 100000 .
, ( ) , :
function wrapper(data){
for (i in data)
this[i] = data[i];
}
wrapper.prototype.test = function(){
"A pretty long string";
}
var array = [];
for (i=0; i<100000; i++)
array[i] = new wrapper({})
, , , , (test, ).
- , "", ( ββ ).