freeCodeCamp/curriculum/challenges/arabic/02-javascript-algorithms-an.../object-oriented-programming/iterate-over-all-properties...

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>&quot;name&quot;</code> .
    testString: 'assert(ownProps.indexOf("name") !== -1, "The <code>ownProps</code> array should include <code>"name"</code>.");'
  - text: يجب أن تتضمن صفيف <code>prototypeProps</code> <code>&quot;numLegs&quot;</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