Behind the scene, is the ES6 class based inheritance is exactly same as es5 prototypal inheritance or not? If not, what is the difference? Is chrome does the same as of ES6 tranpilers, i mean internally compile the es6 classes to function constructor?
Asked
Active
Viewed 125 times
4
-
It's mostly the same. One of the differences is that you can only call an ES6 class constructor using `new`. Not using `new` is an error. – Aadit M Shah Apr 23 '19 at 09:07
-
1Class oriented in JavaScript is just syntactic sugar – FrV Apr 23 '19 at 09:08
2 Answers
1
Under the hood it's the same implementation, "class" in Javascript is just a syntactic sugar.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes
JavaScript classes, introduced in ECMAScript 2015, are primarily syntactical sugar over JavaScript's existing prototype-based inheritance.

Mike Ezzati
- 2,968
- 1
- 23
- 34
0
Browsers will treat it the same if it's supports ES6 class, otherwise your code written in class based inheritance will cause an error on the browser. So one of the difference you could consider is the browser support.

Rannie Aguilar Peralta
- 1,566
- 14
- 19