这就是一个最基础的class类的写法,他有如下的知识点: - Point的类型是function - 在类中定义的方法,可以直接通过this调用constructor中的变量 - 在一个类中,constructor是默认方法,通过 new 命令生成对象实例时自动调用该方法,一个类必须有 constructor 方法,如果没有显示定义,一个空的 constructor 方法会被默认添加。 - 类必须使用 new 来调用,否则就会报错
获取类名
可以通过name属性来获取类名
class Point{} console1.log(Point.name); //"Point"
类中的静态方法
classFoo{
staticclassMethod(){
return'hello';}}
console.log(Foo.classMethod());//hellolet foo=newFoo();
foo.classMethod();//Uncaught TypeError: foo.classMethod is not a function