--- id: 587d7dae367417b2b2512b7b title: Understand Own Properties challengeType: 1 forumTopicId: 301326 localeTitle: Понять собственные свойства --- ## Description
В следующем примере конструктор Bird определяет два свойства: name и numLegs :
функция Bird (name) {
this.name = name;
this.numLegs = 2;
}

пусть утка = новая птица («Дональд»);
let canary = new Bird («Tweety»);
name и numLegs называются own свойствами, поскольку они определяются непосредственно на объекте экземпляра. Это означает, что duck и canary имеют свою отдельную копию этих свойств. Фактически каждый экземпляр Bird будет иметь свою собственную копию этих свойств. Следующий код добавляет все own свойства duck к массиву ownProps :
let ownProps = [];

для (пусть свойство в утке) {
if (duck.hasOwnProperty (свойство)) {
ownProps.push (свойство);
}
}

console.log (ownProps); // печатает ["name", "numLegs"]
## Instructions
Добавьте own свойства canary к массиву ownProps .
## Tests
```yml tests: - text: ownProps should include the values "numLegs" and "name". testString: assert(ownProps.indexOf('name') !== -1 && ownProps.indexOf('numLegs') !== -1); - text: Solve this challenge without using the built in method Object.keys(). testString: assert(!/Object(\.keys|\[(['"`])keys\2\])/.test(code)); - text: Solve this challenge without hardcoding the ownProps array. testString: assert(!/\[\s*(?:'|")(?:name|numLegs)|(?:push|concat)\(\s*(?:'|")(?:name|numLegs)/.test(code)); ```
## Challenge Seed
```js function Bird(name) { this.name = name; this.numLegs = 2; } let canary = new Bird("Tweety"); let ownProps = []; // Add your code below this line ```
## Solution
```js function Bird(name) { this.name = name; this.numLegs = 2; } let canary = new Bird("Tweety"); function getOwnProps (obj) { const props = []; for (let prop in obj) { if (obj.hasOwnProperty(prop)) { props.push(prop); } } return props; } const ownProps = getOwnProps(canary); ```