Skip to content

Instantly share code, notes, and snippets.

@mrboli
Created April 3, 2018 17:44
Show Gist options
  • Select an option

  • Save mrboli/f113821b25ed03c5ec483049edd1618e to your computer and use it in GitHub Desktop.

Select an option

Save mrboli/f113821b25ed03c5ec483049edd1618e to your computer and use it in GitHub Desktop.
function chain(fns) {
let c = {};
let toEx = [];
for (let fn in fns) {
this[fn] = fns[fn];
c.[fn] = function () {
toEx.push({ [fn]: arguments });
}
}
return {
// sum, other functions
execute: function () {
}
}
}
function sum(x, y) {
return x + y;
}
function double(x) {
return sum(x, x);
}
function minus (x, y) {
return x - y;
}
function addOne(x) {
return sum(x, 1);
}
let c = chain({sum, double, minus, addOne});
console.log(c.sum);
c.sum(a, b) // { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment