google / google/closure-compiler

Optimization for extended classes in ADVANCED_OPTIMIZATIONS

Open
#1,874 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

Hello. I have the following javascript code:

```
class Base{
something(){
console.log("base");
}
}

class CoolBase extends Base{
something(){
console.log("cool");
}
}
var a=new CoolBase();
a.something();
```

I'm trying to compile this in ADVANCED_OPTIMIZATIONS .
if I use a simple(not extended) class for example

```
var a=new Base();
a.something();
```

the output is nice and clean: `console.log("base");`

If I use the extended class

```
var a=new CoolBase();
a.something();
```

I get something like this:
`function d(a,b){function e(){}e.prototype=b.prototype;a.prototype=new e;a.prototype.constructor=a;for(var c in b)if(Object.defineProperties){var f=Object.getOwnPropertyDescriptor(b,c);f&&Object.defineProperty(a,c,f)}else a[c]=b[c]}function g(){}g.prototype.a=function(){console.log("base")};function h(){}d(h,g);h.prototype.a=function(){console.log("cool")};(new h).a();`

instead of `console.log("cool");`

It would be nice to optimize this. not sure if it's possible or by fixing this, can lead to other errors.

Thanks

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.