freeCodeCamp/guide/chinese/certifications/javascript-algorithms-and-d.../object-oriented-programming/understand-own-properties/index.md

686 B
Raw Blame History

title localeTitle
Understand Own Properties 了解自己的属性

了解自己的属性

方法:

在给出的示例代码中,您将看到一个新数组ownProps[] intialised然后是for...in语句循环遍历duck的属性,然后使用push()语句填充新数组。对于canary对象必须遵循相同的方法。

只需将'for ... in'语句中的duck对象替换为canary对象即可传递所有测试用例。

解:

let canary = new Bird("Tweety"); 
 let ownProps = []; 
 // Add your code below this line 
 for(let property in canary) { 
  if(canary.hasOwnProperty(property)) { 
    ownProps.push(property); 
  } 
 }