Skip to content

Commit 13d35ad

Browse files
committed
Translate Prototype methods, objects without proto tasks and solutions
1 parent 0a06269 commit 13d35ad

4 files changed

Lines changed: 27 additions & 27 deletions

File tree

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1+
يمكن للدالة أن تأخذ كل الخصائص المعدودة (enumerable) باستخدام `Object.keys` وطباعة قائمة بهم.
12

2-
The method can take all enumerable keys using `Object.keys` and output their list.
3-
4-
To make `toString` non-enumerable, let's define it using a property descriptor. The syntax of `Object.create` allows us to provide an object with property descriptors as the second argument.
3+
لجعل الدالة `toString` غير معدودة (non-enumerable)، سنقوم بتعريفها باستخدام واصف (descriptor). ويسمح لنا شكل `Object.create` أن نضع واصفًا لخاصية كمتغير ثانٍ.
54

65
```js run
76
*!*
87
let dictionary = Object.create(null, {
9-
toString: { // define toString property
10-
value() { // the value is a function
8+
toString: {
9+
value() { // قيمتها عبارة عن دالة
1110
return Object.keys(this).join();
1211
}
1312
}
@@ -17,15 +16,16 @@ let dictionary = Object.create(null, {
1716
dictionary.apple = "Apple";
1817
dictionary.__proto__ = "test";
1918

20-
// apple and __proto__ is in the loop
19+
// apple و __proto__ فى التكرار
2120
for(let key in dictionary) {
22-
alert(key); // "apple", then "__proto__"
23-
}
21+
alert(key); // "apple", ثم "__proto__"
22+
}
2423

2524
// comma-separated list of properties by toString
25+
// قائمة من االخصائص مفصول بينها بالفاصلة
2626
alert(dictionary); // "apple,__proto__"
2727
```
2828

29-
When we create a property using a descriptor, its flags are `false` by default. So in the code above, `dictionary.toString` is non-enumerable.
29+
عند إنشاء خاصية بواصف فإن مُعرِّفاتها تكون قيمها `false`. ولذلك فى الكود أعلاه فإن `dictionary.toString` هي غير معدودة (non-enumerable).
3030

31-
See the the chapter [](info:property-descriptors) for review.
31+
أنظر فصل [](info:property-descriptors) للمراجعة.
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
importance: 5
1+
درجة الأهمية: 5
22

33
---
44

5-
# Add toString to the dictionary
5+
# إضافة الدالة toString إلى القاموس
66

7-
There's an object `dictionary`, created as `Object.create(null)`, to store any `key/value` pairs.
7+
يوجد كائن يسمي `dictionary`، تم إنشاؤه باستخدام `Object.create(null)` لتخزين خصائص بقيمها.
88

9-
Add method `dictionary.toString()` into it, that should return a comma-delimited list of keys. Your `toString` should not show up in `for..in` over the object.
9+
أضف الدالة `dictionary.toString()` لهذا الكائن والتى يجب أن تقوم بإرجاع قائمة من الخصائص بينها الفاصلة. هذا الدالة يجب أن لا تظهر فى التكرار `for..in`.
1010

11-
Here's how it should work:
11+
هنا كيف سيتم استخدامها:
1212

1313
```js
1414
let dictionary = Object.create(null);
1515

1616
*!*
17-
// your code to add dictionary.toString method
17+
// الكود الخاص بك لإنشاء الدالة dictionary.toString
1818
*/!*
1919

20-
// add some data
20+
// أضف بعض البيانات
2121
dictionary.apple = "Apple";
22-
dictionary.__proto__ = "test"; // __proto__ is a regular property key here
22+
dictionary.__proto__ = "test"; // __proto__ هي خاصية عادية
2323

24-
// only apple and __proto__ are in the loop
24+
// تظهر فقط apple & __proto__
2525
for(let key in dictionary) {
26-
alert(key); // "apple", then "__proto__"
26+
alert(key); // "apple", ثم "__proto__"
2727
}
2828

29-
// your toString in action
29+
// استخدام الدالة toString التى صنعتها
3030
alert(dictionary); // "apple,__proto__"
3131
```

1-js/08-prototypes/04-prototype-methods/3-compare-calls/solution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

2-
The first call has `this == rabbit`, the other ones have `this` equal to `Rabbit.prototype`, because it's actually the object before the dot.
2+
الإستدعاء الأول تكون `this == rabbit` والآخرين تكون قيمة `this` مساوية لـ `Rabbit.prototype` وذلك لأنه الكائن قبل النقطة.
33

4-
So only the first call shows `Rabbit`, other ones show `undefined`:
4+
وبالتالى فإن أول استدعاء فقط يعرض `Rabbit` والباقى يعرضون `undefined`:
55

66
```js run
77
function Rabbit(name) {

1-js/08-prototypes/04-prototype-methods/3-compare-calls/task.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
importance: 5
1+
درجة الأهمية: 5
22

33
---
44

5-
# The difference between calls
5+
# الفرق بين الإستدعاءات
66

7-
Let's create a new `rabbit` object:
7+
هيا نقوم بإنشاء كائن جديد يسمي `rabbit`:
88

99
```js
1010
function Rabbit(name) {
@@ -17,7 +17,7 @@ Rabbit.prototype.sayHi = function() {
1717
let rabbit = new Rabbit("Rabbit");
1818
```
1919

20-
These calls do the same thing or not?
20+
هل هذه الإستدعاءات تقوم بنفس الوظيفة أم لا؟
2121

2222
```js
2323
rabbit.sayHi();

0 commit comments

Comments
 (0)