Prototype methods, objects without __proto__ by Amirhossein-Veysi · Pull Request #174 · javascript-tutorial/fa.javascript.info
@@ -1,31 +1,31 @@
The method can take all enumerable keys using `Object.keys` and output their list. این روش میتواند همه کلیدهای شمارشپذیر را با استفاده از `Object.keys` گرفته و فهرست آنها را خروجی کند.
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. برای غیرقابل شمارش کردن `toString`، بیایید آن را با استفاده از یک توصیفگر مشخص کنیم. سینتکس `Object.create` به ما اجازه میدهد تا یک شیء را با توصیفگرهای ویژگی به عنوان آرگومان دوم ارائه کنیم.
```js run *!* let dictionary = Object.create(null, { toString: { // define toString property value() { // the value is a function toString: { // toString تعریف ویژگی value() { // مقدار یک تابع است return Object.keys(this).join(); } } }); */!*
dictionary.apple = "Apple"; dictionary.__proto__ = "test"; dictionary.apple = "سیب"; dictionary.__proto__ = "تست";
// apple and __proto__ is in the loop // در حلقه هستند __proto__ و apple for(let key in dictionary) { alert(key); // "apple", then "__proto__" alert(key); // "__proto__" سپس ،"apple" }
// comma-separated list of properties by toString // toString لیست خصوصیات جدا شده با کاما توسط alert(dictionary); // "apple,__proto__" ```
When we create a property using a descriptor, its flags are `false` by default. So in the code above, `dictionary.toString` is non-enumerable. وقتی یک ویژگی را با استفاده از یک توصیفگر ایجاد میکنیم، پرچمهای آن به طور پیشفرض `false` هستند. بنابراین در کد بالا، `dictionary.toString` غیرقابل شمارش است.
See the the chapter [](info:property-descriptors) for review. برای بررسی به فصل [](info:property-descriptors) مراجعه کنید.
The method can take all enumerable keys using `Object.keys` and output their list. این روش میتواند همه کلیدهای شمارشپذیر را با استفاده از `Object.keys` گرفته و فهرست آنها را خروجی کند.
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. برای غیرقابل شمارش کردن `toString`، بیایید آن را با استفاده از یک توصیفگر مشخص کنیم. سینتکس `Object.create` به ما اجازه میدهد تا یک شیء را با توصیفگرهای ویژگی به عنوان آرگومان دوم ارائه کنیم.
```js run *!* let dictionary = Object.create(null, { toString: { // define toString property value() { // the value is a function toString: { // toString تعریف ویژگی value() { // مقدار یک تابع است return Object.keys(this).join(); } } }); */!*
dictionary.apple = "Apple"; dictionary.__proto__ = "test"; dictionary.apple = "سیب"; dictionary.__proto__ = "تست";
// apple and __proto__ is in the loop // در حلقه هستند __proto__ و apple for(let key in dictionary) { alert(key); // "apple", then "__proto__" alert(key); // "__proto__" سپس ،"apple" }
// comma-separated list of properties by toString // toString لیست خصوصیات جدا شده با کاما توسط alert(dictionary); // "apple,__proto__" ```
When we create a property using a descriptor, its flags are `false` by default. So in the code above, `dictionary.toString` is non-enumerable. وقتی یک ویژگی را با استفاده از یک توصیفگر ایجاد میکنیم، پرچمهای آن به طور پیشفرض `false` هستند. بنابراین در کد بالا، `dictionary.toString` غیرقابل شمارش است.
See the the chapter [](info:property-descriptors) for review. برای بررسی به فصل [](info:property-descriptors) مراجعه کنید.