Skip to content

Instantly share code, notes, and snippets.

@uhop
Created January 21, 2011 00:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uhop/788993 to your computer and use it in GitHub Desktop.
Save uhop/788993 to your computer and use it in GitHub Desktop.
Chaining functions
// 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); }); }
);
@uhop
Copy link
Author

uhop commented Jan 21, 2011

Benchmark it with http://www.perfjs.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment