extending an ES6 class using ES5 syntax?

Boris Zbarsky bzbarsky at mit.edu
Sat May 14 19:25:21 UTC 2016

On 5/14/16 3:11 AM, Andrea Giammarchi wrote:
>  1. why is that?

Why does mutating the proto after an object has been exposed to script 
end up deoptimizing things?  Because it invalidates assumptions JITs 
otherwise make.  So the options are to make the 
proto-hasn't-been-mutated case slower by not making those assumptions or 
to make the proto-has-been-mutated case slower.  Guess which one is a 
better choice?

> There is a
>     spec'd method that is not even on Annex B and Firefox deliberately
>     discourage its usage.

Sure.  Just because something specced doesn't mean it's a good idea to 
actually do it.

This is why in the HTML spec there's all sorts of stuff that's marked as 
"not valid HTML" for authoring purposes even though the spec then goes 
ahead and defines what a browser should do with that stuff if authors do 
it anyway.

> Why I don't see warnings every time I
>     `[].slice.call(arguments)`?

Because that's not as big a performance hit?

> I understand it might de-optimize but I
>     wonder if that's really always necessary (maybe it doesn't have to
>     deopt if it's a well known operation with a predictable result).

I'm not an expert on the type inference setup (which is what ends up 
deoptimizing on proto mutation, iirc), so I can't usefully answer this.

> On the other side, I also wish Firefox woudn't show warnings about
>     modern and recent specifications. Deprecated stuff is OK,

There can totally be things that are both recently added to the spec 
(for UA implementation purposes, because everyone has to do it for web 
compat) and deprecated for authoring purposes (because they're a bad 
idea).  Dynamic proto mutation is one of those.  ;)

>  2. where were you when the `__proto__` landed on specs? :P

You mean when every browser on the market implemented it, which was the 
relevant bit?  The addition to the spec was just acknowledging ugly reality.

Where was I when browsers implemented __proto__?  We're talking 20ish 
years ago, so probably high school or a few years into college.


More information about the es-discuss mailing list