设计模式系列-2.构造函数模式
强制执行构造函数
1 | var Car = function(name, price){ |
其实这真的是JS中无处不在的设计模式
1 | var s = new String('Hello world'); |
延伸考题 new String() 和直接定义真的一样吗
包装函数可以加属性进去1
2s.var_1 = 'var a';
console.log(s.var_1);
原始类型不行, 怎么定义都是undefined1
2
3var string = 'abc';
string.aa = 'bcd';
console.log(string.aa); // undefined