Skip to content

Instantly share code, notes, and snippets.

@StevenBlack
Created December 15, 2012 18:37
Show Gist options
  • Save StevenBlack/4297957 to your computer and use it in GitHub Desktop.
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.
// 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