Created
December 15, 2012 18:37
-
-
Save StevenBlack/4297957 to your computer and use it in GitHub Desktop.
Shows the semantic difference between the terms "defaults", "options", and "settings". * A setting is what your program runs-with in this particular instance. * A default is what your program runs-with in the absence of a provided option.
* An option is a user-provided value that overrides a default.
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
// assuming jQuery for its extend method. | |
// Calling program does this, and passes-in the options | |
var options = { validate: true, name: "bar" }; | |
function myThing ( options ) { | |
// Internally your program does this | |
var empty = {} | |
var defaults = { validate: false, limit: 5, name: "foo" }; | |
// The Keys to the City right here in this next line | |
// Note: Defaults are preserved for subsequent calls | |
// Note: User-provided options are preserved | |
var settings = $.extend( empty, defaults, options) ; | |
// ... etc using variable settings as required | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment