-
-
Save mxriverlynn/5cfa341cfb548547c388 to your computer and use it in GitHub Desktop.
the problem with options.change && options.change();
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
options.change && options.change(); |
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
if (options.change){ options.change(); } | |
// or | |
if ("change" in options) { options.change(); } | |
// or | |
if (Object.hasOwnProperty.call(options, "change")) { options.change(); } | |
// or ... |
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
var options = { | |
foo: "bar" | |
}; |
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
if (_.isFunction(options.change)){ | |
options.change(); | |
} |
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
// 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