uhateoas
8/19/2013 - 1:54 PM

Function Chaining Pattern This pattern is a nice way to organize the public interface of your module. It saves time and improves readabilit

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);