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"]
own
canary
إلى مجموعة ownProps
. ownProps
القيم "numLegs"
و "name"
.
testString: 'assert(ownProps.indexOf("name") !== -1 && ownProps.indexOf("numLegs") !== -1, "ownProps
should include the values "numLegs"
and "name"
.");'
- text: حل هذا التحدي دون استخدام الأسلوب Object.keys()
.
testString: 'assert(!/\Object.keys/.test(code), "Solve this challenge without using the built in method Object.keys()
.");'
```