一、为什么需要分类
理由一
有很多对象拥有一样的属性和行为,需要把他们分为同一类
这样创建类似对象的时候很方便
理由二
对象拥有其他的属性和行为,就需要不同的分类
而Object穿件出来的对象,是最没有特点的对象
二、对象的分类
常见的有:
Array
Function
Date
RegExp
三、声明\使用方式
class Circle{
constructor(radius){
this.radius = radius
}
getArea(){
return Math.pow(this.radius,2) * Math.PI
}
getLength(){
return this.radius * 2 * Math.PI
}
}
let circle = new Circle(5)
circle.radius
circle.getArea()
circle.getLength()