Last active
January 28, 2017 11:35
-
-
Save railsstudent/352cee62633795bde5a3c34774b40c3f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function chainFunctions(fns) { | |
for (let fname in fns) { | |
let originalFn = fns[fname]; | |
let fn = (...inputs) => { | |
if (this.result != null) { | |
inputs.splice(0, 0, this.result); | |
} | |
let cloneCF = new chainFunctions(fns); | |
cloneCF.result = originalFn.apply(this, inputs); | |
return cloneCF | |
}; | |
Object.defineProperty(this, fname, { value: fn }); | |
} | |
} | |
chainFunctions.prototype.execute = function() { return this.result; } | |
function chain(fns) { | |
return new chainFunctions(fns); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment