Bird构造函数定义了两个属性: name和numLegs : function Bird(name){
this.name = name;
this.numLegs = 2;
}
让鸭子=新鸟(“唐纳德”);
让金丝雀=新鸟(“特威蒂”);
name和numLegs称为own属性,因为它们直接在实例对象上定义。这意味着duck和canary每个都有自己独立的这些属性的副本。事实上, Bird每个实例都有自己的这些属性的副本。下面的代码将所有的own的性质duck到阵列ownProps : 让ownProps = [];
for(let duck in duck){
if(duck.hasOwnProperty(property)){
ownProps.push(属性);
}
}
的console.log(ownProps); //打印[“name”,“numLegs”]
canary own属性添加到数组ownProps 。 ownProps应包含值"numLegs"和"name" 。
testString: 'assert(ownProps.indexOf("name") !== -1 && ownProps.indexOf("numLegs") !== -1, "ownProps should include the values "numLegs" and "name".");'
- text: 无需使用内置方法Object.keys()即可解决此挑战。
testString: 'assert(!/\Object.keys/.test(code), "Solve this challenge without using the built in method Object.keys().");'
```