es6

ES6 教程 - JavaScript 教程

 ES6 类

之前

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

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

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

之后

class Person {
    constructor(name) {
        this.name = name;
    }
    getName() {
        return this.name;
    }
}
posted @ 2025-04-22 15:44  流星曳尾  阅读(5)  评论(0)    收藏  举报