Skip to content

Instantly share code, notes, and snippets.

@rmccullagh
Created July 28, 2014 00:15
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 rmccullagh/9f3cfc585f0fd92a2583 to your computer and use it in GitHub Desktop.
Save rmccullagh/9f3cfc585f0fd92a2583 to your computer and use it in GitHub Desktop.
three different ways of writing the same thing
function fn() {
var args = Array.prototype.slice.call(arguments);
var node;
var i = 0;
while(node = args.shift()) {
if(typeof node == 'function') {
node();
console.log("Function found at index %d", i);
break;
}
++i;
}
}
function fn1() {
for(var i = 0, args = Array.prototype.slice.call(arguments); i < args.length; ++i) {
if(typeof args[i] == 'function') {
args[i]();
console.log("Function found at index %d", i);
}
}
};
function fn2() {
for(var i = 0; i < arguments.length; i++) {
if('function' == typeof arguments[i]) {
arguments[i]();
console.log("Function found at index %d", i);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment