Created
September 4, 2018 12:21
-
-
Save andycochrane/6ae89afcdfe92eab37f48f48c43dd0ee to your computer and use it in GitHub Desktop.
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 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