I'm getting an error on Maximum call stack size for this code.
function ValueObject() {
}
ValueObject.prototype.authentication;
Object.defineProperty(ValueObject.prototype, "authentication", {
get : function () {
return this.authentication;
},
set : function (val) {
this.authentication = val;
}
});
var vo = new ValueObject({last: "ac"});
vo.authentication = {a: "b"};
console.log(vo);
Error
RangeError: Maximum call stack size exceeded
set
function is executed each time the assignment happens. There is no point in usingdefineProperty
in your code. What you are defining is the pre-defined behavior. – Euonymus