own属性和prototype属性。 Own属性直接在对象实例本身上定义。和prototype属性所定义的prototype 。 function Bird(name){以下是如何将
this.name = name; //拥有财产
}
Bird.prototype.numLegs = 2; //原型属性
让鸭子=新鸟(“唐纳德”);
duck own属性添加到数组ownProps和prototype属性到数组prototypeProps : 让ownProps = [];
让prototypeProps = [];
for(let duck in duck){
if(duck.hasOwnProperty(property)){
ownProps.push(属性);
} else {
prototypeProps.push(属性);
}
}
的console.log(ownProps); //打印[“名称”]
的console.log(prototypeProps); //打印[“numLegs”]
own的属性beagle到数组ownProps 。将Dog所有prototype属性添加到数组prototypeProps 。 ownProps数组应包含"name" 。
testString: 'assert(ownProps.indexOf("name") !== -1, "The ownProps array should include "name".");'
- text: prototypeProps数组应该包含"numLegs" 。
testString: 'assert(prototypeProps.indexOf("numLegs") !== -1, "The prototypeProps array should include "numLegs".");'
- text: 无需使用内置方法Object.keys()即可解决此挑战。
testString: 'assert(!/\Object.keys/.test(code), "Solve this challenge without using the built in method Object.keys().");'
```