* fix: Chinese test suite Add localeTiltes, descriptions, and adjust test text and testStrings to get the automated test suite working. * fix: ran script, updated testStrings and solutions
2.2 KiB
2.2 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d7daf367417b2b2512b7d | Iterate Over All Properties | 1 | 迭代所有属性 |
Description
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”]
Instructions
own
的属性beagle
到数组ownProps
。将Dog
所有prototype
属性添加到数组prototypeProps
。 Tests
tests:
- text: <code>ownProps</code>数组应包含<code>"name"</code> 。
testString: assert(ownProps.indexOf('name') !== -1);
- text: <code>prototypeProps</code>数组应该包含<code>"numLegs"</code> 。
testString: assert(prototypeProps.indexOf('numLegs') !== -1);
- text: 无需使用内置方法<code>Object.keys()</code>即可解决此挑战。
testString: assert(!/\Object.keys/.test(code));
Challenge Seed
function Dog(name) {
this.name = name;
}
Dog.prototype.numLegs = 4;
let beagle = new Dog("Snoopy");
let ownProps = [];
let prototypeProps = [];
// Add your code below this line
Solution
// solution required