Created
December 9, 2021 11:26
-
-
Save MrMeison/9132942122eb7d2f559f0e9ee0ff64ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1 вариант: выхов от результата. Пример задача на суммирование. | |
const fn = (...args) => { | |
const wrapper = () => { | |
return fn; | |
} | |
return wrapper; | |
} | |
console.log(fn()()()()); | |
// 2 вариант: Чейнинг. Суть в возращении того же самого или экземляра того самого, пример: JQuery | |
class Calc { | |
constructor(initValue) { | |
this.value = initValue; | |
} | |
add(value) { | |
this.value += value; | |
return this; | |
} | |
} | |
console.log(new Calc(3).add(4).add(5)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment