I am trying to annotate my javascript so that closure doesnt rename all the symbols since i am working with vanilla javascript as well.
/**
* @constructor
* @expose
* @type{foo}
*/
foo = function (el, args) {
"use strict";
var s = "Hello World";
/*
* @expose
* @this {foo}
* @type {function}
*/
this.introduce = function () {
return s;
};
};
However the generated output when i run it through the closure compiler with advanced optimization is
foo = function() {
this.a = function() {
return"Hello World"
} };
How do i ask closure to preserve the name introduce since this will be called from an external javascript.
The following options may be used to prevent the Closure Compiler from renaming symbols:
@export
(also see:goog.exportSymbol
orgoog.exportProperty
)@expose
has been deprecatedIf you do not want to define methods on the function prototype as shown in your example, then you could export the constructor
foo
withgoog.exportSymbol
and use@expose
to export methods.By defining methods on the function prototype,
goog.exportSymbol
can be used to export both the constructor as well as method names.See these related stackoverflow questions: