2.9 KiB
2.9 KiB
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d7daf367417b2b2512b7d | Iterate Over All Properties | 1 | تكرار جميع الممتلكات |
Description
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"]
Instructions
own
beagle
إلى مجموعة ownProps
. إضافة كل خصائص prototype
Dog
إلى مجموعة prototypeProps
. Tests
tests:
- text: يجب أن تتضمن صفيف <code>ownProps</code> <code>"name"</code> .
testString: 'assert(ownProps.indexOf("name") !== -1, "The <code>ownProps</code> array should include <code>"name"</code>.");'
- text: يجب أن تتضمن صفيف <code>prototypeProps</code> <code>"numLegs"</code> .
testString: 'assert(prototypeProps.indexOf("numLegs") !== -1, "The <code>prototypeProps</code> array should include <code>"numLegs"</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>.");'
Challenge Seed
function Dog(name) {
this.name = name;
}
Dog.prototype.numLegs = 4;
let beagle = new Dog("Snoopy");
let ownProps = [];
let prototypeProps = [];
// Add your code below this line
Solution
// solution required