编辑: Cerise银子 | 2019-12-24 |
简介 2. 设计模式 i. 构造器模式 Table of Contents 每日一题
2 分类目创建学习知识点 每个知识点尽可能小,读者可以花几分钟时间学习理解 每日一题 每日一题
3 简介 Design patterns 每日一题
4 设计模式 定义一个函数,然后通过new去调用构造函数创建对象 function People(name, age){ this.name = name;
this.age = age;
} People.prototype.setName = function(name){ this.name = name;
};
People.prototype.sayName = function(){ console.log('我的名字叫' + this.name);
};
var p1 = new People('饥人谷BAT讲师团', 20);
p1.sayName();
var p2 = new People('若愚');
p2.setName('禄永');
p2.sayName();
输出: 我的名字叫饥人谷BAT讲师团 我的名字叫禄永 构造器模式 每日一题
5 构造器模式