2021-07-14
es6 class 中constructor和super
1.JavaScript语言的传统方法是通过构造函数,定义并生成新对象
function Parent(name) {
this.name = name
}
Parent.prototype.sayHi = function () {
console.log('hi, ' + this.name)
}
基本上,ES6的class可以看作只是一个语法糖,它的绝大部分功能,ES5都可以做到,新的class写法只是让对象原型的写法更加清晰、更像
翻译
2021-07-14 16:26:31 ·
87 阅读 ·
0 评论