You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/09-classes/07-mixins/article.md
+13-13Lines changed: 13 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -107,24 +107,24 @@ new User("Dude").sayHi(); // Hello Dude!
107
107
108
108
## EventMixin
109
109
110
-
Now let's make a mixin for real life.
110
+
حالا بیایید یک mixin برای زندگی واقعی بسازیم.
111
111
112
-
An important feature of many browser objects (for instance) is that they can generate events. Events are a great way to "broadcast information" to anyone who wants it. So let's make a mixin that allows us to easily add event-related functions to any class/object.
112
+
یک خاصیت مهم در تعداد زیادی از شیءهای مرورگر (برای مثال) این است که آنها میتوانند رویداد (event) ایجاد کنند. رویدادها راهی عالی برای «انتشار اطلاعات» به هر کسی که آن را بخواهد هستند. پس بیایید یک mixin بسازیم که به ما این امکان را میدهد تا به راحتی تابعهای مربوط به رویداد را به هر شیء/کلاسی اضافه کنیم.
113
113
114
-
-The mixin will provide a method `.trigger(name, [...data])`to "generate an event" when something important happens to it. The`name`argument is a name of the event, optionally followed by additional arguments with event data.
115
-
-Also the method `.on(name, handler)`that adds `handler`function as the listener to events with the given name. It will be called when an event with the given `name`triggers, and get the arguments from the `.trigger`call.
116
-
- ...And the method `.off(name, handler)`that removes the `handler`listener.
114
+
-این mixin متد `.trigger(name, [...data])`را برای «ایجاد یک رویداد» زمانی که اتفاقی برای آن میافتد فراهم میکند. آرگومان`name`اسم رویداد است که بعد از آن آرگومانهای اضافی اختیاری شامل دادۀ رویداد میآید.
115
+
-همچنین متد `.on(name, handler)`را فراهم میکند که تابع `handler`را به عنوان کنترلکننده به رویدادهایی با نام داده شده اضافه میکند. این تابع زمانی که رویدادی همراه با `name`داده شده راه میافتد (trigger) اجرا میشود و آرگومانها را از فراخوانی `.trigger`دریافت میکند.
116
+
- ...و متد `.off(name, handler)`را هم فراهم میکند که کنترلکننده `handler`را حذف میکند.
117
117
118
-
After adding the mixin, an object`user`will be able to generate an event `"login"`when the visitor logs in. And another object, say,`calendar`may want to listen for such events to load the calendar for the logged-in person.
118
+
بعد از اضافه کردن `mixin`، یک شیء`user`خواهد توانست زمانی که بازدیدکننده وارد میشود (log in) یک رویداد `"login"`ایجاد کند. و شیء دیگر، مثلا`calendar`(تقویم) شاید بخواهد چنین رویدادهایی را کنترل کند تا تقویم را برای شخص وارد شده بارگیری کند.
119
119
120
-
Or, a`menu`can generate the event `"select"`when a menu item is selected, and other objects may assign handlers to react on that event. And so on.
120
+
یا یک`menu`(فهرست) میتواند زمانی که چیزی از فهرست انتخاب شود رویداد `"select"`(انتخاب) را ایجاد کند و شیءهای دیگر ممکن است کنترلکنندههایی را برای واکنش دادن به این رویداد داشته باشند. و مثالهایی دیگر.
121
121
122
-
Here's the code:
122
+
اینجا کد آن را داریم:
123
123
124
124
```js run
125
125
let eventMixin = {
126
126
/**
127
-
* Subscribe to event, usage:
127
+
* :متعهد ساختن به یک رویداد، کاربرد
128
128
* menu.on('select', function(item) { ... }
129
129
*/
130
130
on(eventName, handler) {
@@ -136,7 +136,7 @@ let eventMixin = {
136
136
},
137
137
138
138
/**
139
-
* Cancel the subscription, usage:
139
+
* :لغو کردن تعهد، کاربرد
140
140
* menu.off('select', handler)
141
141
*/
142
142
off(eventName, handler) {
@@ -150,15 +150,15 @@ let eventMixin = {
150
150
},
151
151
152
152
/**
153
-
* Generate an event with the given name and data
153
+
* ایجاد یک رویداد همراه با داده و نام داده شده
154
154
* this.trigger('select', data1, data2);
155
155
*/
156
156
trigger(eventName, ...args) {
157
157
if (!this._eventHandlers?.[eventName]) {
158
-
return; //no handlers for that event name
158
+
return; //کنترلکنندهای برای این نام رویداد وجود ندارد
0 commit comments