Last active
September 8, 2016 05:50
-
-
Save coderatchet/03b34fdf2bef2bfc9216be8fde5c9242 to your computer and use it in GitHub Desktop.
default values for keys in a configuration object for a function using goog.object.extend()
This file contains hidden or 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
/** | |
* @typedef {{ | |
* exportFormat: string, | |
* renderFormat: string, | |
* exportArguments: Array }} | |
*/ | |
some.namespace.MyClass.ARGUMENTS; | |
/** | |
* @param {some.namespace.MyClass.ARGUMENTS=} opt_config optional configuration object | |
*/ | |
some.namespace.MyClass = function(opt_config) { | |
/** @ type {!some.namespace.MyClass.ARGUMENTS} */ | |
this.config_ = goog.object.extend({ | |
textContent: 'default', | |
tagType: 'text-link', | |
applyArguments: [] | |
}, opt_config); | |
}; | |
/* neater, easier to read and non-stringy */ |
This file contains hidden or 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
/** | |
* @param {object=} opt_config optional configuration object | |
*/ | |
some.namespace.MyClass = function(opt_config) { | |
/* ... */ | |
this.config_ = opt_config | |
goog.object.setIfUndefined(config_, 'exportFormat', 'default'); | |
goog.object.setIfUndefined(config_, 'renderFormat', 'text-link'); | |
goog.object.setIfUndefined(config_, 'exportArguments', []); | |
/* ... */ | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment