2.2 KiB
Raw Blame History

id, title, challengeType, videoUrl, localeTitle
id title challengeType videoUrl localeTitle
587d7dae367417b2b2512b7b Understand Own Properties 1 了解自己的属性

Description

在以下示例中, Bird构造函数定义了两个属性: namenumLegs
function Birdname{
this.name = name;
this.numLegs = 2;
}

让鸭子=新鸟(“唐纳德”);
让金丝雀=新鸟(“特威蒂”);
namenumLegs称为own属性,因为它们直接在实例对象上定义。这意味着duckcanary每个都有自己独立的这些属性的副本。事实上, Bird每个实例都有自己的这些属性的副本。下面的代码将所有的own的性质duck到阵列ownProps
让ownProps = [];

forlet duck in duck{
ifduck.hasOwnPropertyproperty{
ownProps.push属性;
}
}

的console.logownProps; //打印[“name”“numLegs”]

Instructions

canary own属性添加到数组ownProps

Tests

tests:
  - text: <code>ownProps</code>应包含值<code>&quot;numLegs&quot;</code>和<code>&quot;name&quot;</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