own
وخواص prototype
. يتم تعريف الخصائص Own
مباشرة على مثيل الكائن نفسه. يتم تعريف خصائص prototype
على prototype
. وظيفة الطيور (الاسم) {هنا هو كيف يمكنك إضافة
this.name = name؛ //الملكية الخاصة
}
Bird.prototype.numLegs = 2؛ // الملكية النموذج
السماح بطة = الطيور الجديدة ("دونالد") ؛
duck
الصورة own
خصائص لمجموعة ownProps
و prototype
خصائص لمجموعة prototypeProps
: let ownProps = []؛
السماح لـ prototypeProps = []؛
ل (دع الممتلكات في البط) {
if (duck.hasOwProProty (property)) {
ownProps.push (الملكية)؛
} آخر {
prototypeProps.push (الملكية)؛
}
}
console.log (ownProps)؛ // printts ["name"]
console.log (prototypeProps)؛ // prints ["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()
.");'
```