前端的设计模式 -- 构造函数模式

构造函数模式

function Person(name,age){
    this.name = name;
    this.age = age;
}
Person.prototype = {
    constructor: Person;
    printName: function(){
        console.log(this.name);
    },
    printAge: function(){
        console.log(this.age);
    }
}

var person = new Person('xin', 22);
person.printName(); // xin
person.printAge(); // 22

.

posted @ 2019-11-08 21:35  每天都要进步一点点  阅读(249)  评论(0编辑  收藏  举报