If I have an array of three objects:
var array = [obj1, obj2, obj3];
And my objects has one specific property (example: "id") and two common properties (example: "prop" and "log" function)..
I wonder which one would have least memory usage? What's better to use?
Defining the same properties on all items of my array:
var obj1 = {id: 1, prop: '@', log: function() { console.log('TEST'); }};
var obj2 = {id: 2, prop: '@', log: function() { console.log('TEST'); }};
var obj3 = {id: 3, prop: '@', log: function() { console.log('TEST'); }};
var array = [obj1, obj2, obj3];
vs.
Creating objects (items of my array) with a given prototype
var myProto = {prop: '@', log: function() { console.log('TEST'); }};
var obj1 = Object.create(myProto);
obj1.id = 1;
var obj2 = Object.create(myProto);
obj2.id = 2;
var obj3 = Object.create(myProto);
obj3.id = 3;
var array = [obj1, obj2, obj3];
vs.
Create a object with the common properties and extend my array items to use this object
var common = {prop: '@', log: function() { console.log('TEST'); }};
var obj1 = extend({id: 1}, common);
var obj2 = extend({id: 2}, common);
var obj3 = extend({id: 3}, common);
var array = [obj1, obj2, obj3];