freeCodeCamp/curriculum/challenges/arabic/02-javascript-algorithms-an.../object-oriented-programming/understand-own-properties.a...

2.6 KiB

id title challengeType videoUrl localeTitle
587d7dae367417b2b2512b7b Understand Own Properties 1 فهم خصائص خاصة

Description

في المثال التالي ، يعرف منشئ Bird خاصيتين: name و numLegs :
وظيفة الطيور (الاسم) {
this.name = name؛
this.numLegs = 2 ،
}

السماح بطة = الطيور الجديدة ("دونالد") ؛
السماح الكناري = الطيور الجديدة ("تويتي") ؛
name و numLegs تسمى الخصائص own ، لأنها محددة مباشرة على كائن مثيل. وهذا يعني أن كل من duck canary له نسخة منفصلة خاصة به من هذه الخصائص. في الواقع ، سيكون لكل نسخة من Bird نسخة خاصة بها من هذه الخصائص. التعليمة البرمجية التالية يضيف كل من own خصائص duck لمجموعة ownProps :
let ownProps = []؛

ل (دع الممتلكات في البط) {
if (duck.hasOwProProty (property)) {
ownProps.push (الملكية)؛
}
}

console.log (ownProps)؛ // prints ["name"، "numLegs"]

Instructions

إضافة الخصائص own canary إلى مجموعة ownProps .

Tests

tests:
  - text: يجب أن تتضمن <code>ownProps</code> القيم <code>&quot;numLegs&quot;</code> و <code>&quot;name&quot;</code> .
    testString: 'assert(ownProps.indexOf("name") !== -1 && ownProps.indexOf("numLegs") !== -1, "<code>ownProps</code> should include the values <code>"numLegs"</code> and <code>"name"</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 Bird(name) {
  this.name = name;
  this.numLegs = 2;
}

let canary = new Bird("Tweety");
let ownProps = [];
// Add your code below this line

Solution

// solution required