Skip to content

Instantly share code, notes, and snippets.

@beeblesox
Created March 16, 2014 19:17
Show Gist options
  • Save beeblesox/9588349 to your computer and use it in GitHub Desktop.
Save beeblesox/9588349 to your computer and use it in GitHub Desktop.
Function definition patterns
/*** 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