own
свойства и свойства prototype
. Own
свойства определяются непосредственно на самом экземпляре объекта. И prototype
определены на prototype
. функция Bird (name) {Вот как вы добавляете
this.name = name; //собственность
}
Bird.prototype.numLegs = 2; // свойство прототипа
пусть утка = новая птица («Дональд»);
own
свойства duck
к массиву ownProps
и свойства prototype
для массива prototypeProps
: let ownProps = [];
let prototypeProps = [];
для (пусть свойство в утке) {
if (duck.hasOwnProperty (свойство)) {
ownProps.push (свойство);
} else {
prototypeProps.push (свойство);
}
}
console.log (ownProps); // печатает ["name"]
console.log (prototypeProps); // печатает ["numLegs"]
own
свойства beagle
в массив ownProps
. Добавьте все свойства prototype
Dog
в массив prototypeProps
.
ownProps
array should include "name"
.
testString: assert(ownProps.indexOf('name') !== -1);
- text: The prototypeProps
array should include "numLegs"
.
testString: assert(prototypeProps.indexOf('numLegs') !== -1);
- text: Solve this challenge without using the built in method Object.keys()
.
testString: assert(!/\Object.keys/.test(code));
```