一、Class基本语法
class和构造函数类似,用于生成新对象。
class Point {
constructor(x, y) {
this.x = x; // 属性
this.y = y;
}
toString() { // 方法
return '(' + this.x + ', ' + this.y + ')';
}
}
- 方法之间不需要逗号分隔,加了分号会报错
- 类的所有方法都定义在类的prototype属性上且内部定义的所有方法都是不可枚举的。
- contructor方法没有写的话会默认添加一个空的constructor方法,constructor方法默认返回实例对象(this),也可以返回另一个对象(A)&#