This is how I create objects from a hash of properties:
var object = new function (data) {
var self = this;
self.property = data.property;
self.anotherProperty = data.anotherProperty;
self.method = function () { return 'something'; }
self.update = function (newData) {
//what is here ?
//i could have written:
self.property = newData.property;
self.anotherProperty = newData.anotherProperty;
//but why not reuse the constructor?
}
};
I wonder how to reuse this function (constructor) to update an object from hash.
So that:
object.update(newData)
would update current object properties from newData hash the same way it is done in the constructor function.
By giving the constructor a name?
you can can now call
and
i hope this helps.. i not 100% sure, because i’m learning too.. but yeah try it 😉
edit: after reading this comment of you: “But that would return a new instance, wouldn’t it? Which i don’t want.”
i think you can write the Update function and call it in your constructor
;