Created
February 6, 2016 23:55
-
-
Save danday74/e56ae8bbe6e35fc10ab5 to your computer and use it in GitHub Desktop.
JavaScript chaining 2
This file contains hidden or 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
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