[英]Are object properties value constants in Object.create?
这是一个非常奇怪的问题,我一直在学习一些Javascript,并且我的代码可以运行,但是我想了解为什么会这样:
当在Object.create之外创建att和def提升但属性hp作为常量工作时,为什么可以使它们起作用?
let Pokemon = { def: this.def, att: this.att, defBoost: function() { this.def = this.def + this.def return this.def; }, attBoost: function() { this.att = this.att + this.att return this.att; }, hpBoost: function() { this.hp = this.hp + this.hp return this.hp; } } let psyduck = Object.create(Pokemon, { name: { value: "Psyduck" }, hp: { value: 500 } }); psyduck.def = 12; psyduck.att = 20; console.log(psyduck); psyduck.attBoost(); psyduck.defBoost(); psyduck.hpBoost(); console.log(psyduck);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.