Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native Prototypes #250

Merged
merged 2 commits into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -6,8 +6,8 @@ Function.prototype.defer = function(ms) {
};

function f() {
alert("Hello!");
alert("Привіт!");
}

f.defer(1000); // shows "Hello!" after 1 sec
f.defer(1000); // показує "Привіт!" через 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!");
alert("Привіт!");
}

f.defer(1000); // shows "Hello!" after 1 second
f.defer(1000); // показує "Привіт!" через 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); // показує 3 після 1 сек
```

Please note: we use `this` in `f.apply` to make our decoration work for object methods.
Будь ласка, зверніть увагу: ми використовуємо `this` в `f.apply`, щоб наше декорування працювало для методів об’єкта.

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 All @@ -29,7 +29,7 @@ Function.prototype.defer = function(ms) {
};

let user = {
name: "John",
name: "Іван",
sayHi() {
alert(this.name);
}
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); // показує 3 після 1 секунди
```

Please note that the arguments should be passed to the original function.
Будь ласка, зверніть увагу, що аргументи повинні бути передані до вихідної функції.
Loading