摘要:
1.//需要装饰的类(函数)function Macbook() { this.cost = function () { return 1000; };}function Memory(macbook) { this.cost = function () { return macbook.cost() + 75; };}function BlurayDrive(macbook) { this.cost = function () { return macbook.cost() + 300; };}function I... 阅读全文
摘要:
1.简单工厂/* BicycleShop class. */var BicycleShop = function() {};BicycleShop.prototype = { sellBicycle: function(model) { var bicycle; switch(model) { case 'The Speedster': bicycle = new Speedster(); break; case 'The Lowrider': bicycle = new Lowrider(); ... 阅读全文
摘要:
1.var Singleton = (function () { var instantiated; function init() { /*这里定义单例代码*/ return { publicMethod: function () { console.log('hello world'); }, publicProperty: 'test' }; } return { getInstance: function () ... 阅读全文