Created
November 24, 2012 16:24
-
-
Save tjmehta/4140367 to your computer and use it in GitHub Desktop.
Last arg function
This file contains 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
var fn = function(one, two, three, callback) { | |
var args = Array.prototype.slice.apply(arguments); | |
var lastArg = args.pop() | |
if (callback !== lastArg && typeof lastArg == 'function') { | |
callback = lastArg; | |
arguments[args.length] = undefined; // not -1 bc of pop above | |
} | |
// Handle undefined values, by setting default value | |
// .. Rest of function .. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment