Does this still happen if you enable type (dis)ambiguation?
http://closuretools.blogspot.com/2011/01/property-by-any-other-name-part-3.html
http://code.google.com/p/closure-compiler/wiki/ExperimentalTypeBasedPropertyRenaming
On Wed, Dec 5, 2012 at 7:17 PM, Josh <
php...@gmail.com> wrote:
> I'm not sure whether the following is a bug or by design. Consider the code
> below; Closure Compiler's advanced optimizations has no problem inlining
> getSomething() and renaming Thing.someName but it won't touch getAttribute()
> or Thing.attrName unless externs are disabled. I guess this is because
> getAttribute() and the attrName property are part of the DOM externs, but I
> thought Closure Compiler would make out that this "Thing" object is not
> related to Element (the object that declares getAttribute()) and no amount
> of extra annotations seems to help.
>
> Is it a bug or just an unfortunate side-effect? Thanks for any info.
>
> /** @constructor */
> function Thing(x) {
> this.attrName = x;
> this.someName = x;
> }
> Thing.prototype = {
> getAttribute: function() { return this.attrName; },
> getSomething: function() { return this.someName; }
> }
> alert(new Thing("x").getAttribute());
> alert(new Thing("y").getSomething());
>
> # With default externs, gets compiled to
> function
> a(b){this.a=this.attrName=b}a.prototype={getAttribute:function(){return
> this.attrName}};alert((new a("x")).getAttribute());alert((new a("y")).a);
>
> # Without default externs
> function a(b){this.b=this.a=b}a.prototype={};alert((new
> a("x")).a);alert((new a("y")).b);