Created
August 29, 2011 21:17
-
-
Save JakubOboza/1179431 to your computer and use it in GitHub Desktop.
before filter for js 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
function sample(a, b){ | |
return console.log(a + b); | |
} | |
function argless(){ | |
console.log("Argless lol"); | |
} | |
function before(foo, filter, args){ | |
return function(){ | |
filter(); | |
return foo.apply(foo, args); | |
} | |
} | |
function after(foo, filter, args){ | |
return function(){ | |
var result = foo.apply(foo, args); | |
filter(); | |
return result; | |
} | |
} | |
var f = before(argless, function(){ console.log("before"); }); | |
f = before(f, function(){ console.log("beforer then before"); }); | |
f = after(f, function(){ console.log("after");} ); | |
f = before(f, function(){ console.log("before between afters chain")}); | |
f = after(f, function(){ console.log("afterer");} ); | |
f = before(f, function(){ console.log("beforeer then beforer then before"); }); | |
f(); | |
var k = before(sample, function(){console.log("before");}, [1,2]); | |
k(); | |
// add bindings | |
// make it more reliable for exceptions | |
// enjoy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment