I have a JavaScript object created from JSON. I really need to set its prototype property to be a different object because of JS5 getters and setters. Here is an example of what I need that works on Chrome:
function MyObj() { }
MyObj.prototype = {
get myProp : function () { return this._myProp; },
set myProp : function (arg) { this._myProp = arg; }
}
... stuff ...
var instance = JSON.parse(result);
instance.constructor = MyObj;
instance.__proto__ = MyObj.prototype;
With this code, I can get and set properties on instance
using the getters and setters defined in the prototype. However, this is not portable and will not work on IE, (nor node, I think).
What is the proper and portable way of doing this?