var yinhang = Object.create(Object.prototype,{
type : {
value : "建设银行",
writable : true,
enumerable : true
},
money : {
get : function() {
if(typeof money === "undefined" ) {
return "账户中没有钱";
}
return money;
},
set : function(num) {
money+=num;
return "账户中有"+money
}
}
});
yinhang.money
// "账户中没有钱"
yinhang.money = 1000
VM893:16 Uncaught ReferenceError: money is not defined(…)
为什么给money赋值会报错呢?
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
认证高级PHP讲师