Created
March 16, 2014 19:17
-
-
Save beeblesox/9588349 to your computer and use it in GitHub Desktop.
Function definition patterns
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
/*** function statement vs variable ****/ | |
function myFunc(){} | |
// vs | |
var myFunc = function(){}; | |
/***** Argument signature *****/ | |
// Standard | |
function standardFunction(arg1, arg2){ | |
// Argument type detection allows more flexible/optional arguments | |
if (typeof arguments[0] == "string") | |
// first arg is a string | |
arguments[0]; | |
} | |
// { name: value } pairs | |
function useObjectAsArguments(args){ | |
args.name; | |
// this way, all arguments can be optional, passed in any order, and accessed by name | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment