ES6 Class类

1.function

function Person(name) {
    this.name = name;
}

Person.prototype.getName = function () {
    return this.name;
};

var john = new Person("John Doe");
console.log(john.getName());

2.class

class Person {
    constructor(name) {
        this.name = name;
    }
    getName() {
        return this.name;
    }
}

 

posted @ 2021-07-05 10:19  留下成长的足迹  阅读(21)  评论(0编辑  收藏  举报