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
должен содержать "name"
.
testString: 'assert(ownProps.indexOf("name") !== -1, "The ownProps
array should include "name"
.");'
- text: Массив prototypeProps
должен содержать "numLegs"
.
testString: 'assert(prototypeProps.indexOf("numLegs") !== -1, "The prototypeProps
array should include "numLegs"
.");'
- text: 'Решите эту задачу, не используя встроенный метод Object.keys()
.'
testString: 'assert(!/\Object.keys/.test(code), "Solve this challenge without using the built in method Object.keys()
.");'
```