Skip to content

Instantly share code, notes, and snippets.

@bradleykronson
Created August 19, 2013 13:54
Show Gist options
  • Save bradleykronson/6269382 to your computer and use it in GitHub Desktop.
Save bradleykronson/6269382 to your computer and use it in GitHub Desktop.
Function Chaining Pattern This pattern is a nice way to organize the public interface of your module. It saves time and improves readability:
var User = {
profile: {},
name: function(value) {
this.profile.name = value;
return this;
},
job: function(value) {
this.profile.job = value;
return this;
},
getProfile: function() {
return this.profile;
}
};
var profile = User.name("Krasimir Tsonev").job("web developer").getProfile();
console.log(profile);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment