es6的 class
es6 只是一个语法糖,底层还是原型链。例如:
// 构造函数写法
function Point(x, y) {
this.x = x;
this.y = y;
}
Point.prototype.toString = function () {
return '(' + this.x + ', ' + this.y + ')';
};
var p = new Point(1, 2);
// es6 类的写法
class Point {
constructor(x, y) {
转载
2021-09-02 16:03:10 ·
71 阅读 ·
0 评论