Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save andycochrane/6ae89afcdfe92eab37f48f48c43dd0ee to your computer and use it in GitHub Desktop.
Save andycochrane/6ae89afcdfe92eab37f48f48c43dd0ee to your computer and use it in GitHub Desktop.
/*
* Function with options object parameter
*
* Dependencies
* ------------
* An extend helper function or the jquery extend method to merge the defaults
* and options objects.
*
* 1. Merge defaults and options objects into new settings object.
* 2. Assign variables to settings properties.
*/
function functionWithOptionsParameter(options) {
var defaults = {
optionOne: true,
optionTwo: 1000,
optionThree: 'string'
};
var settings = extend({}, defaults, options); /* [1] */
var optionOne = settings.optionOne,
optionTwo = settings.optionTwo,
optionThree = settings.optionThree; /* [2] */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment