我在这段代码中遇到了“最大调用堆栈大小”错误。
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);
错误
RangeError: Maximum call stack size exceeded
set
函数。在您的代码中使用defineProperty
没有意义。您正在定义预定义行为。 - Ram