If I create custom objects through functions like this:
function createCustomObject ( state ) {
let obj = { state };
obj.doSomething = function ( ) {
// do something
};
return obj;
}
let myNewObject = createCustomObject( { foo: 'bar' } );
myNewObject.doSomething();
How does that work out memory-wise? Does JavaScript keep a separate copy of the doSomething
method for each of the objects I create? If I need to create thousands of objects will using prototypes/composition be more efficient?