Skip to content

Instantly share code, notes, and snippets.

@yoshuawuyts
Last active August 29, 2015 14:00
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 yoshuawuyts/11341840 to your computer and use it in GitHub Desktop.
Save yoshuawuyts/11341840 to your computer and use it in GitHub Desktop.
'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