Last active
August 29, 2015 14:00
-
-
Save yoshuawuyts/11341840 to your computer and use it in GitHub Desktop.
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
'use strict'; | |
/** | |
* Exports | |
*/ | |
exports = module.exports = container; | |
/** | |
* Function chaining example | |
* | |
* The function returns the object with the modified values, | |
* thus allowing for method chaining. Makes for a clean, | |
* functional syntax. | |
* | |
* container.add(5).add(4) | |
* -> 9 | |
*/ | |
function container() { | |
if (!(this instanceof container)) return new container; | |
this.value = 0; | |
}; | |
/** | |
* Add number | |
* | |
* @param {Number} num | |
* @return {Number} | |
* @api public | |
*/ | |
container.prototype.add = function(num) { | |
this.value += num; | |
return this; | |
} | |
/** | |
* Log to console | |
* | |
* Remember to call the object with 'container()', else | |
* most properties won't be initialized. | |
*/ | |
console.log(container().add(5).add(4)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment