Created
July 28, 2014 00:15
-
-
Save rmccullagh/9f3cfc585f0fd92a2583 to your computer and use it in GitHub Desktop.
three different ways of writing the same thing
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 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