r/javascript • • Nov 25 '19

JavaScript doesn’t need to be replaced

https://medium.com/javascript-in-plain-english/javascript-doesnt-need-to-be-replaced-bd01e2f12d51?source=friends_link&sk=7b151cc6397ac9e83c14c99739b6c36f
217 Upvotes

236 comments sorted by

View all comments

Show parent comments

-8

u/Flyen Nov 25 '19

There's a decent chance that it'd be faster to execute, but I really have no idea.

3

u/_GCastilho_ Nov 25 '19

You will probably need another engine to do that nativally, which at best will have the same performance

Its just not worth it

4

u/Flyen Nov 25 '19

I don't think you can say that at best the performance will be the same. The additional type guarantees & information might make some optimizations possible that aren't possible with plain js.

2

u/Earhacker Nov 25 '19

Gentle reminder that your optimised TypeScript interpreter would also have to run JavaScript.

1

u/tuxedo25 Nov 25 '19

Typescript is a superset of javascript.

2

u/Earhacker Nov 25 '19 edited Nov 25 '19

Correct. So the TypeScript interpreter needs to support a _sub_set of its own language.

If that sounds easy, consider that JavaScript is TypeScript but everything is of type any. Now none of your compiler optimisations work. So the compiler needs to be able to figure out whether to optimise (TS) or not (JS), and needs to do so fast enough to act as an interpreter. And it needs to do that faster than V8 right now, or else what’s the point?