Skip to content

Instantly share code, notes, and snippets.

@alexymik
Created June 27, 2015 00:10
Show Gist options
  • Save alexymik/6cc618ece6785e7afeda to your computer and use it in GitHub Desktop.
Save alexymik/6cc618ece6785e7afeda to your computer and use it in GitHub Desktop.
JavaScript Chaining
function add(num1, num2) {
chain = function(num2) { return num1 + num2 };
if (num2) {
return chain(num2)
} else {
return chain
}
};
console.log(add(2, 2)); // 4
console.log(add(2)(2)); // 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment