Skip to content

Instantly share code, notes, and snippets.

@MrMeison
Created December 9, 2021 11:26
Show Gist options
  • Save MrMeison/9132942122eb7d2f559f0e9ee0ff64ed to your computer and use it in GitHub Desktop.
Save MrMeison/9132942122eb7d2f559f0e9ee0ff64ed to your computer and use it in GitHub Desktop.
// 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