__extends and ES5 target

Topics: General
May 27, 2014 at 2:32 PM
I see that the generated __extends() uses the same code in ES3/ES5 targets even if in ES5 it can be simplified with Object.create and Object.getOwnPropertyNames making the whole function probably unnecessary. Is it an oversite?
May 27, 2014 at 4:13 PM
It's very intentional that the function exists at all -- many people want to use a custom __extends function, so there needs to be something for them to hook in to (hence why we write __extends = this.__extends || ...).

We talked about possibly emitting different code depending on the target, but it wasn't really worth the effort. You can really only shave a few bytes off the code by using ES5, and the added complexity didn't justify the cost. It turns out to be rather tricky because you have to have the two implementations be 100% identical in every aspect, behavior-wise, if you don't want to create some very nasty problems at runtime.
May 27, 2014 at 6:12 PM
@igorbukanov That function also copies the static properties (i.e. class level inheritance), which is required for ES6 class inheritance compliance.