.github
api-server
client
config
curriculum
challenges
_meta
arabic
chinese
01-responsive-web-design
02-javascript-algorithms-and-data-structures
basic-algorithm-scripting
basic-data-structures
basic-javascript
debugging
es6
functional-programming
intermediate-algorithm-scripting
javascript-algorithms-and-data-structures-projects
object-oriented-programming
add-methods-after-inheritance.chinese.md
change-the-prototype-to-a-new-object.chinese.md
create-a-basic-javascript-object.chinese.md
create-a-method-on-an-object.chinese.md
define-a-constructor-function.chinese.md
extend-constructors-to-receive-arguments.chinese.md
inherit-behaviors-from-a-supertype.chinese.md
iterate-over-all-properties.chinese.md
make-code-more-reusable-with-the-this-keyword.chinese.md
override-inherited-methods.chinese.md
remember-to-set-the-constructor-property-when-changing-the-prototype.chinese.md
reset-an-inherited-constructor-property.chinese.md
set-the-childs-prototype-to-an-instance-of-the-parent.chinese.md
understand-own-properties.chinese.md
understand-the-constructor-property.chinese.md
understand-the-immediately-invoked-function-expression-iife.chinese.md
understand-the-prototype-chain.chinese.md
understand-where-an-objects-prototype-comes-from.chinese.md
use-a-constructor-to-create-objects.chinese.md
use-a-mixin-to-add-common-behavior-between-unrelated-objects.chinese.md
use-an-iife-to-create-a-module.chinese.md
use-closure-to-protect-properties-within-an-object-from-being-modified-externally.chinese.md
use-dot-notation-to-access-the-properties-of-an-object.chinese.md
use-inheritance-so-you-dont-repeat-yourself.chinese.md
use-prototype-properties-to-reduce-duplicate-code.chinese.md
verify-an-objects-constructor-with-instanceof.chinese.md
regular-expressions
03-front-end-libraries
04-data-visualization
06-information-security-and-quality-assurance
08-coding-interview-prep
09-certificates
english
portuguese
russian
spanish
formattingConversion
math-challenges
requiresTests
schema
test
.babelrc
.editorconfig
.eslintignore
.eslintrc
.npmignore
.prettierrc
.travis.yml
CHANGELOG.md
LICENSE.md
commitizen.config.js
commitlint.config.js
create-challenge-bundle.js
getChallenges.js
gulpfile.js
index.js
lib.js
md-translation.js
package-entry.js
package-lock.json
package.json
repack.js
unpack.js
unpacked.css
unpacked.js
unpackedChallenge.js
utils.js
docs
guide
mock-guide
tools
.editorconfig
.eslintignore
.eslintrc
.gitattributes
.gitignore
.node-inspectorrc
.prettierrc
.snyk
.travis.yml
.vcmrc
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE.md
README.french.md
README.italian.md
README.md
docker-compose-shared.yml
docker-compose.yml
lerna.json
netlify.toml
package-lock.json
package.json
sample.env
59 lines
2.2 KiB
Markdown
59 lines
2.2 KiB
Markdown
![]() |
---
|
|||
|
id: 587d7dae367417b2b2512b7b
|
|||
|
title: Understand Own Properties
|
|||
|
challengeType: 1
|
|||
|
videoUrl: ''
|
|||
|
localeTitle: 了解自己的属性
|
|||
|
---
|
|||
|
|
|||
|
## Description
|
|||
|
<section id="description">在以下示例中, <code>Bird</code>构造函数定义了两个属性: <code>name</code>和<code>numLegs</code> : <blockquote> function Bird(name){ <br> this.name = name; <br> this.numLegs = 2; <br> } <br><br>让鸭子=新鸟(“唐纳德”); <br>让金丝雀=新鸟(“特威蒂”); </blockquote> <code>name</code>和<code>numLegs</code>称为<code>own</code>属性,因为它们直接在实例对象上定义。这意味着<code>duck</code>和<code>canary</code>每个都有自己独立的这些属性的副本。事实上, <code>Bird</code>每个实例都有自己的这些属性的副本。下面的代码将所有的<code>own</code>的性质<code>duck</code>到阵列<code>ownProps</code> : <blockquote>让ownProps = []; <br><br> for(let duck in duck){ <br> if(duck.hasOwnProperty(property)){ <br> ownProps.push(属性); <br> } <br> } <br><br>的console.log(ownProps); //打印[“name”,“numLegs”] </blockquote></section>
|
|||
|
|
|||
|
## Instructions
|
|||
|
<section id="instructions">将<code>canary</code> <code>own</code>属性添加到数组<code>ownProps</code> 。 </section>
|
|||
|
|
|||
|
## Tests
|
|||
|
<section id='tests'>
|
|||
|
|
|||
|
```yml
|
|||
|
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>.");'
|
|||
|
|
|||
|
```
|
|||
|
|
|||
|
</section>
|
|||
|
|
|||
|
## Challenge Seed
|
|||
|
<section id='challengeSeed'>
|
|||
|
|
|||
|
<div id='js-seed'>
|
|||
|
|
|||
|
```js
|
|||
|
function Bird(name) {
|
|||
|
this.name = name;
|
|||
|
this.numLegs = 2;
|
|||
|
}
|
|||
|
|
|||
|
let canary = new Bird("Tweety");
|
|||
|
let ownProps = [];
|
|||
|
// Add your code below this line
|
|||
|
|
|||
|
```
|
|||
|
|
|||
|
</div>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</section>
|
|||
|
|
|||
|
## Solution
|
|||
|
<section id='solution'>
|
|||
|
|
|||
|
```js
|
|||
|
// solution required
|
|||
|
```
|
|||
|
</section>
|