I love how Google Closure compiler will optimize symbols in code. However, I have not found a good way to define public, exported functions that take configuration objects as parameters. Consider this code snippet:
goog.provide('foo');
goog.require('goog.dom');
/** @typedef {{
* id : string,
* clazz : string
* }}
*/
foo.config;
/**
* Does some neat stuff
* @param {foo.config} config
*/
foo.myFoo = function(config) {
var el = goog.dom.getElement(config.id);
goog.dom.classes.add(el, config.clazz);
}
goog.exportSymbol('foo.myFoo', foo.myFoo);
Now assume we load this script, and want to call myFoo as follows:
<script type="text/javascript">
foo.myFoo({
id: 'unique-id',
clazz: 'pretty'
});
</script>
If compiled, this would fail because id and clazz properties were compressed.
Does anyone know of an elegant way to implement and export configuration objects using the Google Closure compiler?