I want to turn a plain JavaScript object into one with a prototype etc, without cloning the object. Is this possible?
Essentially, instead of this:
var MyClass = function(fromObj) {
this.propA = fromObj.propA;
this.propB = fromObj.propB;
...
}
inherit (SuperClass, MyClass);
I would like to:
var MyClass = function(fromObj) {
this = fromObj;
}
inherit (SuperClass, MyClass);
To be extra clear: I would like the object returned from the constructor to be the same object that was passed in (not a duplicate, not a clone).
Is there a way to achieve this? Or a better way to describe what I'm asking for? :)
I'd like this for two reasons:
- We're loading a lot of objects, and speed and memory may start to matter.
- There are lots of places where the "plain old javascript objects" are used, and it may be hard to make sure they all point to the new instantiated object.