ES6 class 和 ES5 function constructor 有什么区别?
What are the differences between ES6 class and ES5 function constructors?
题目类型: 技术面试题
这是一道技术面试题,常见于澳洲IT公司面试中。
难度: medium
分类: javascript-fundamentals
标签: class, constructor, prototype
参考答案摘要
答案 本质上 ES6 class 仍然基于原型,但提供了更清晰的语法糖(constructor、extends、super、static)。 class 声明有 TDZ(不像 function constructor 的函数声明那样可随意在前调用),且默认处于严格模式;类方法不可枚举。 class 更适合表达面向对象结构,但仍建议在 JS 中优先组合而非过度继承。
本题提供 STAR 原则详细解答和技术解析,登录匠人学院学习中心即可查看完整答案。