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

构造函数模式

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

.

原文地址:https://www.cnblogs.com/crazycode2/p/11823421.html