Skip to content

Instantly share code, notes, and snippets.

@danday74
Created February 6, 2016 23:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danday74/e56ae8bbe6e35fc10ab5 to your computer and use it in GitHub Desktop.
Save danday74/e56ae8bbe6e35fc10ab5 to your computer and use it in GitHub Desktop.
JavaScript chaining 2
var chain = (function() {
var count = 0;
function Inner() {
var self = this;
self.funcA = function(num) { count += num; return self; }
self.funcB = function() { count += 2; return self; }
self.ok = function() { var result = count; count=0; return result; }
}
return new Inner();
}());
var result1 = chain.funcA(6).funcB().ok();
var result2 = chain.funcA(7).funcB().ok();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment