Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ function f() {
alert("Hello!");
}

f.defer(1000); // shows "Hello!" after 1 sec
f.defer(1000); // را نشان می‌دهد "Hello!" بعد از 1 ثانیه
```
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ importance: 5

---

# Add method "f.defer(ms)" to functions
# متد "f.defer(ms)" را به تابع‌ها اضافه کنید

Add to the prototype of all functions the method `defer(ms)`, that runs the function after `ms` milliseconds.
متد `defer(ms)` را به پروتوتایپ تمام تابع‌ها اضافه کنید که تابع را بعد از `ms` میلی‌ثانیه اجرا می‌کند.

After you do it, such code should work:
بعد از اینکه آن را انجام دادید، چنین کدی باید کار کند:

```js
function f() {
alert("Hello!");
}

f.defer(1000); // shows "Hello!" after 1 second
f.defer(1000); // را نشان می‌دهد "Hello!" بعد از 1 ثانیه
```
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ Function.prototype.defer = function(ms) {
}
};

// check it
// آن را بررسی کنید
function f(a, b) {
alert( a + b );
}

f.defer(1000)(1, 2); // shows 3 after 1 sec
f.defer(1000)(1, 2); // بعد از 1 ثانیه 3 را نمایش می‌دهد
```

Please note: we use `this` in `f.apply` to make our decoration work for object methods.
لطفا توجه کنید: ما در `f.apply` از `this` استفاده کردیم تا کاری کنیم که دکور کردن برای متدهای شیء هم کار کند.

So if the wrapper function is called as an object method, then `this` is passed to the original method `f`.
پس اگر تابع دربرگیرنده به عنوان متد شیء فراخوانی شود، سپس `this` به متد اصلی `f` پاس داده می‌شود.

```js run
Function.prototype.defer = function(ms) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ importance: 4

---

# Add the decorating "defer()" to functions
# دکوراتور "defer()" را به تابع‌ها اضافه کنید

Add to the prototype of all functions the method `defer(ms)`, that returns a wrapper, delaying the call by `ms` milliseconds.
متد `defer(ms)` را به پروتوتایپ تمام تابع‌ها اضافه کنید که یک دربرگیرنده را برمی‌گرداند و فراخوانی را به اندازه `ms` میلی‌ثانیه به تاخیر می‌اندازد.

Here's an example of how it should work:
این کد نمونه‌ای چگونگی کار کردن آن است:

```js
function f(a, b) {
alert( a + b );
}

f.defer(1000)(1, 2); // shows 3 after 1 second
f.defer(1000)(1, 2); // بعد از 1 ثانیه 3 را نمایش می‌دهد
```

Please note that the arguments should be passed to the original function.
لطفا در نظر داشته باشید که آرگومان‌ها باید به تابع اصلی پاس داده شوند.
Loading