Fluent Programming

Fluent programming is a technique which allow us to perform a sequential workflow with a chain of method calls. The trick is to use the same method as getter/setter depending on the presence or not of a parameter. If a parameter is not provided then the method is a getter and returns its value. If a parameter is provided the the method is a setter and returns the whole object after performing the update. In this way we can chain several setter methods to perform a more complex task.

var _value = value;
_self.value = function (value) {
    if (value === undefined)
        return _value;
    else {
        _value = value;
        return _self;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s