Skip to content

Instantly share code, notes, and snippets.

@cori
Forked from mxriverlynn/1.js
Last active August 29, 2015 14:25
Show Gist options
  • Save cori/c852832a7f4e34665b53 to your computer and use it in GitHub Desktop.
Save cori/c852832a7f4e34665b53 to your computer and use it in GitHub Desktop.
options.change && options.change();
if (options.change){ options.change(); }
// or
if ("change" in options) { options.change(); }
// or
if (Object.hasOwnProperty.call(options, "change")) { options.change(); }
// or ...
var options = {
change: "foo"
};
if (_.isFunction(options.change)){
options.change();
}
// explicit separation of options and options persistence
function doStuff(options, optionsPersistence){
options.set("something", "that value");
options.set("whatever", 1234.1234);
// assume the save method is there, because that's what
// the API "contract" or "protocol" says should be there
if (optionsPersistence) {
optionsPersistence.save(options);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment