If I take this code and compile it (advanced optimizations)
/**@constructor*/
function MyObject() {
this.test = 4
this.toString = function () {return 'test object'}
}
window['MyObject'] = MyObject
I get this code
window.MyObject=function(){this.test=4;this.toString=function(){return"test object"}};
Is there any way I can remove the toString function using the Closure Compiler?
toString
is implicitly callable, so unless the Closure compiler can prove that the result ofMyObject
is never coerced to a string it has to preserve it.You can always mark it as explicit debug code:
then in your non-debug build, compile with
See http://closure-library.googlecode.com/svn/docs/closure_goog_base.js.source.html which does