摘要: 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... 阅读全文
posted @ 2013-02-21 17:02 瓦尔登湖的秋天 阅读(144) 评论(0) 推荐(0) 编辑
摘要: 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(); ... 阅读全文
posted @ 2013-02-21 15:57 瓦尔登湖的秋天 阅读(151) 评论(0) 推荐(0) 编辑
摘要: 1.var Singleton = (function () { var instantiated; function init() { /*这里定义单例代码*/ return { publicMethod: function () { console.log('hello world'); }, publicProperty: 'test' }; } return { getInstance: function () ... 阅读全文
posted @ 2013-02-21 14:33 瓦尔登湖的秋天 阅读(126) 评论(0) 推荐(0) 编辑