Skip to content

Instantly share code, notes, and snippets.

@vestige
Created December 11, 2012 13:42
Show Gist options
  • Select an option

  • Save vestige/4258649 to your computer and use it in GitHub Desktop.

Select an option

Save vestige/4258649 to your computer and use it in GitHub Desktop.
mchain.js
var obj = {
value: 1,
increment: function () {
this.value += 1;
return this;
},
add: function (v) {
this.value += v;
return this;
},
shout: function () {
alert(this.value);
}
};
document.writeln(obj.increment().add(3).shout());
document.writeln(obj.increment());
document.writeln(obj.add(3));
document.writeln(obj.shout());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment