Skip to content

Commit 8942ba5

Browse files
authored
Merge pull request #174 from Amirhossein-Veysi/master
Prototype methods, objects without proto
2 parents b714660 + 607ebd2 commit 8942ba5

File tree

5 files changed

+105
-105
lines changed

5 files changed

+105
-105
lines changed
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11

2-
The method can take all enumerable keys using `Object.keys` and output their list.
2+
این روش می‌تواند همه کلیدهای شمارش‌پذیر را با استفاده از `Object.keys` گرفته و فهرست آنها را خروجی کند.
33

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.
4+
برای غیرقابل شمارش کردن `toString`، بیایید آن را با استفاده از یک توصیفگر مشخص کنیم. سینتکس `Object.create` به ما اجازه می‌دهد تا یک شیء را با توصیفگرهای ویژگی به عنوان آرگومان دوم ارائه کنیم.
55

66
```js run
77
*!*
88
let dictionary = Object.create(null, {
9-
toString: { // define toString property
10-
value() { // the value is a function
9+
toString: { // toString تعریف ویژگی
10+
value() { // مقدار یک تابع است
1111
return Object.keys(this).join();
1212
}
1313
}
1414
});
1515
*/!*
1616

17-
dictionary.apple = "Apple";
18-
dictionary.__proto__ = "test";
17+
dictionary.apple = "سیب";
18+
dictionary.__proto__ = "تست";
1919

20-
// apple and __proto__ is in the loop
20+
// در حلقه هستند __proto__ و apple
2121
for(let key in dictionary) {
22-
alert(key); // "apple", then "__proto__"
22+
alert(key); // "__proto__" سپس ،"apple"
2323
}
2424

25-
// comma-separated list of properties by toString
25+
// toString لیست خصوصیات جدا شده با کاما توسط
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` غیرقابل شمارش است.
3030

31-
See the the chapter [](info:property-descriptors) for review.
31+
برای بررسی به فصل [](info:property-descriptors) مراجعه کنید.

1-js/08-prototypes/04-prototype-methods/2-dictionary-tostring/task.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@ importance: 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)` ایجاد شده است تا هر جفت `key/value` را ذخیره کند.
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()` را به آن اضافه کنید، که باید فهرستی از کلیدها با کاما را برگرداند. `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
21-
dictionary.apple = "Apple";
22-
dictionary.__proto__ = "test"; // __proto__ is a regular property key here
20+
// اضافه کردن مقداری داده
21+
dictionary.apple = "سیب";
22+
dictionary.__proto__ = "تست"; // یک ویژگی معمولی است __proto__ در اینجا
2323

24-
// only apple and __proto__ are in the loop
24+
// در حلقه وجود دارند __proto__ تنها سیب و
2525
for(let key in dictionary) {
26-
alert(key); // "apple", then "__proto__"
26+
alert(key); // "__proto__" سپس ،"apple"
2727
}
2828

29-
// your toString in action
30-
alert(dictionary); // "apple,__proto__"
29+
// شما در عمل toString
30+
alert(dictionary); // "سیب,__proto__"
3131
```

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

Lines changed: 4 additions & 4 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+
بنابراین فقط اولین تماس `خرگوش` را نشان می‌دهد، سایر تماس‌ها `undefined` را نشان می‌دهند:
55

66
```js run
77
function Rabbit(name) {
@@ -11,9 +11,9 @@ Rabbit.prototype.sayHi = function() {
1111
alert( this.name );
1212
}
1313

14-
let rabbit = new Rabbit("Rabbit");
14+
let rabbit = new Rabbit("خرگوش");
1515

16-
rabbit.sayHi(); // Rabbit
16+
rabbit.sayHi(); // خرگوش
1717
Rabbit.prototype.sayHi(); // undefined
1818
Object.getPrototypeOf(rabbit).sayHi(); // undefined
1919
rabbit.__proto__.sayHi(); // undefined

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
@@ -2,9 +2,9 @@ importance: 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) {
@@ -14,10 +14,10 @@ Rabbit.prototype.sayHi = function() {
1414
alert(this.name);
1515
};
1616

17-
let rabbit = new Rabbit("Rabbit");
17+
let rabbit = new Rabbit("خرگوش");
1818
```
1919

20-
These calls do the same thing or not?
20+
این فراخوانی‌ها همین کار را می‌کنند یا نه؟
2121

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

0 commit comments

Comments
 (0)