2.2 KiB
2.2 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d7dae367417b2b2512b7b | Understand Own Properties | 1 | 了解自己的属性 |
Description
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”]
Instructions
canary
own
属性添加到数组ownProps
。 Tests
tests:
- text: <code>ownProps</code>应包含值<code>"numLegs"</code>和<code>"name"</code> 。
testString: 'assert(ownProps.indexOf("name") !== -1 && ownProps.indexOf("numLegs") !== -1, "<code>ownProps</code> should include the values <code>"numLegs"</code> and <code>"name"</code>.");'
- text: 无需使用内置方法<code>Object.keys()</code>即可解决此挑战。
testString: 'assert(!/\Object.keys/.test(code), "Solve this challenge without using the built in method <code>Object.keys()</code>.");'
Challenge Seed
function Bird(name) {
this.name = name;
this.numLegs = 2;
}
let canary = new Bird("Tweety");
let ownProps = [];
// Add your code below this line
Solution
// solution required