Created
April 17, 2016 17:17
-
-
Save ernestlv/fe574e241634f3b8aa45a4d73d49f914 to your computer and use it in GitHub Desktop.
Pipes two functions
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
/* | |
Pipes two functions | |
*/ | |
function pipe(fn, fnPipe, obj){ | |
var fnx = function(){}; | |
if (typeof fn === 'function'){ | |
fnx = function(){ | |
var res = fn.apply(this, [].slice.apply(arguments)); | |
return typeof fnPipe === 'function' ? fnPipe.call(this, res) : res; | |
}.bind(obj || window); | |
}else{ | |
console.log('pipe warning not a function:', fn); | |
} | |
return fnx; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment