02 2013 档案

摘要:命令模式是一种封装方法调用的方式,它用来对方法进行参数化处理和传送,经这样处理方法可以在任何需要的时候执行。适用于两种情况,一是消除调用操作的对象和实现操作的对象之间的耦合,二是在创建用户界面方面,特别是需要不受限的取消操作的时候。缺点在于增加复杂度,难以调试,所以一般不要强用。1.简单命令对象一般用来消除接收者和调用者的耦合var SimpleCommand = function(receiver) { // implements Command this.receiver = receiver;};SimpleCommand.prototype.execute = function() . 阅读全文
posted @ 2013-02-25 15:50 瓦尔登湖的秋天 阅读(165) 评论(0) 推荐(0) 编辑
摘要:1.传统模式validator = { validate: function (value, type) { switch (type) { case 'isNonEmpty ': { return true; // NonEmpty 验证结果 } case 'isNumber ': ... 阅读全文
posted @ 2013-02-25 13:52 瓦尔登湖的秋天 阅读(156) 评论(0) 推荐(0) 编辑
摘要:1.function Publisher() { this.subscribers = [];}Publisher.prototype.deliver = function(data) { this.subscribers.forEach( function(fn) { fn(data); } ); return this;};Function.prototype.subscribe = function(publisher) { var that = this; var alreadyExists = publisher.subscribers.some( ... 阅读全文
posted @ 2013-02-22 11:30 瓦尔登湖的秋天 阅读(147) 评论(0) 推荐(0) 编辑
摘要:1.本体var Publication = new Interface('Publication', ['getIsbn', 'setIsbn', 'getTitle', 'setTitle', 'getAuthor', 'setAuthor', 'display']);var Book = function(isbn, title, author) { ... } // implements Publication/* Library interface. */va 阅读全文
posted @ 2013-02-22 11:04 瓦尔登湖的秋天 阅读(164) 评论(0) 推荐(0) 编辑
摘要:DED.util.Event = { getEvent: function(e) { return e || window.event; }, getTarget: function(e) { return e.target || e.srcElement; }, stopPropagation: function(e) { if (e.stopPropagation) { e.stopPropagation(); } else { e.cancelBubble = true; } }, preventDefault: f... 阅读全文
posted @ 2013-02-22 10:45 瓦尔登湖的秋天 阅读(153) 评论(0) 推荐(0) 编辑
摘要: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 瓦尔登湖的秋天 阅读(150) 评论(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 瓦尔登湖的秋天 阅读(154) 评论(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) 编辑