简体   繁体   中英

Is the ES6 class based inheritance is same like es5 prototypal inheritance

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM