I'm extending Object.create()
to take a second argument e.g
if (typeof Object.create !== 'function') {
Object.create = function (o,arg) {
function F() {}
F.prototype = o;
return new F(arg);
};
}
//could be multiple of these objects that hold data
var a = {
b : 2
};
var c = function(data){
return{
d : Object.create(data)
};
};
//create new instance of c object and pass some data
var newObj = function(arg){
return(Object.create(c(arg)))
}
var e = newObj(a);
e.d.b = 5;
var f = newObj(a);
console.log(e.d.b);
console.log(f.d.b);
I'm just wondering if there are any pitfalls to using Object.create()
in this way? I would do some extra checking on the arg argument in the Object.create()
function if I was to use this but the main point is to find out if this causes any issues or is overkill etc..