short question: Can i use objects as value inside of a defineProperty call? Currently i have the problem that all instances of a class share the same object.
Little example:
var Test = function () {
};
var p = Test.prototype;
Object.defineProperty(p, 'object', {
value: new TestObject(),
enumerable: true,
writeable: false
});
A simple test case:
var x = new Test();
var y = new Test();
y.object.test = 'Foobar';
console.log(x.object.test); // --> Foobar
At the moment i must solve this problem on this way:
var Test = function () {
this.initialize();
};
var p = Test.prototype;
p._object = null;
p.initialize = function () {
this._object = new TestObject();
};
Object.defineProperty(p, 'object', {
get: function () { return this._object; },
enumerable: true
});
It is possible to get a solution without a extra property?