On Sat, Jul 22, 2017 at 3:17 PM, Andrea Giammarchi <
[email protected]> wrote:
> ```js
> class List extends Array { }
>
> console.log(new List instanceof List);
> // false .. seriously
> ```
>
> Try it yourself. [1]
>
I don't have a horse in the TypeScript race, but that example is unfair:
The playground targets ES5 by default. As you know, you can't correctly
subclass Array with ES5 features. To get the expected `instanceof` result
from that code in ES5-land, TypeScript would have to replace uses of
`instanceof` with something of its own, sacrificing efficiency for a
questionable gain (`instanceof` usually smells anyway). (It *is*
unfortunate that http://www.typescriptlang.org/docs/handbook/classes.html
doesn't mention this.)
But ES5 output is just an option; if you tell TypeScript to output ES2015
code instead (`tsc --target ES2015 example.ts`), you get the expected
result. Note that Babel targeting ES5 output also outputs "false":
https://goo.gl/aJuQjV (that's just a shortened version of the Babel link
resulting from pasting the code above into https://babeljs.io/repl)
If necessary, let's have a reasonable discussion of whether TypeScript's
co-opting of keywords and syntax has a negative effect on the evolution of
JavaScript (if that's a useful conversation to have), but let's not blame
TypeScript for ES5's deficiencies, particularly not ones that were fixed
more than two years ago.
-- T.J. Crowder
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss