Last active
July 15, 2017 19:23
-
-
Save akari0624/1c3dead4a02299ae828315f6d12c93a9 to your computer and use it in GitHub Desktop.
dollarSignCanDoAggregate.js
This file contains 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
(function(global) { | |
global.$ = function(initNum) { | |
var aggregate = initNum; | |
return { | |
add: function(plusNum) { | |
aggregate += plusNum; | |
return this; | |
}, | |
result: function() { | |
return aggregate; | |
} | |
}; | |
} | |
} | |
)(window); | |
// for test | |
console.log($(1).add(2).add(3).add(4).result()); | |
console.log($(2).add(5).result()); | |
console.log($(7).add(2).add(100).add(9).result()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment