JavaScript - Chaining Sample

by Ryan Morris

JavaScript

var baseObject = {
    x: 22,
    setX: function (x) {
        this.x = x;
        console.log(this);
        return this;
    },
    setY: function (y) {
        this.y = y;
        console.log(this);
        return this;
    },
    setZ: function (z) {
        this.z = z;
        console.log(this);
        return this;
    }
}

baseObject.setX(5).setY(6).setZ(7);