js之es6中类的创建

class Person{

    constructor(name,age){

    this.name = name;

    this.age = age;

    }

    showName(){

    alert(this.name)

    }

};

var p2 = new Person('张三',20);
p2.showName();

使用关键字class创建类

使用new关键字创建对象

posted @ 2020-03-13 14:16  你有我备注吗  阅读(192)  评论(0)    收藏  举报