Created
January 21, 2011 00:12
-
-
Save uhop/788993 to your computer and use it in GitHub Desktop.
Chaining 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
// chaining functions | |
var flag = 0; | |
var list = [ | |
function(f){}, | |
function(f){}, | |
function(f){}, | |
function(f){ flag = f; } | |
]; | |
var N = list.length; | |
function chain(i, arg){ | |
list[i](arg); | |
var next = i + 1; | |
if(next < N){ | |
chain(next, arg); | |
} | |
} | |
this.group( | |
"chains", | |
function recur(){ chain(0, 1); }, | |
function iter(){ | |
for(var i = 0; i < N; ++i){ | |
list[i](2); | |
} | |
}, | |
function iter2(){ list.forEach(function(f){ f(3); }); } | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Benchmark it with http://www.perfjs.com/