JSFiddle - React, Tailwind, and code Playground
JavaScript
var chainable = (function (slice) {
var Chainable = {
init: function (obj) {
this._obj = obj;
return this;
},
chain: function (fn) {
var obj = this._obj;
this._result = obj[fn].apply(obj, slice.call(arguments, 1));
return this;
},
end: function () {
return this._result;
}
};
return function (obj) {
return Object.create(Chainable).init(obj);
};
})(Array.prototype.slice);
var o = {
setTest: function (test) {
this.test = test;
},
getTest: function () {
return this.test;
}
};
console.log(chainable(o).chain('setTest', 'test').chain('getTest').end());