Created
August 19, 2013 13:54
-
-
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:
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
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