2013年7月7日

共享原型

摘要: /** * 共享原型 * 原理: js中对象按引用传递 *///facade 一个输出函数function log() { console.log([].join.call(arguments, ','));}//第一个类function One(name) { this.name = name || "Adam";}//第一个类原型上添加一个方法One.prototype.say = function() { return this.name;}//实现共享原型function share_prototype(one, two) { two.prototy 阅读全文

posted @ 2013-07-07 22:58 mtima 阅读(202) 评论(0) 推荐(0)

使用apply或call实现借用构造函数实现继承

摘要: //facade 一个输出函数function log() { console.log([].join.call(arguments, ','));}//父类function Parent(name) { this.name = name || "Adam";}//为父类原型上添加一个方法Parent.prototype.say = function() { return this.name;}//子类function Child(name) { //调用父类的构造函数,并作用于子类 Parent.apply(this,arguments);}//用父类的实 阅读全文

posted @ 2013-07-07 22:45 mtima 阅读(349) 评论(0) 推荐(0)

等比缩略图宽高算法

摘要: $dstScale) { $sampleWidth = $dstWidth; $sampleHeight = $dstHeight/$srcScale; } else { $sampleWidth = $dstHeight; $sampleHeight = $dstWidth*$srcScale; } $dstImg = imagecreatetruecolor($sampleWidth, $sampleHeight); // 制作缩略图 imagecopyresampled($dstImg, $s... 阅读全文

posted @ 2013-07-07 17:07 mtima 阅读(454) 评论(0) 推荐(0)

facade模式

摘要: > *//** * * 我们来看一下不使用facade模式比较极端的一个例子 * 以下代码只是为了从log中获取信息,并将其转为对象数据 */function getProductFileLines($file) { return file($file);}function getProductObjectFromId($id, $productName) { return new Product($id, $productName);}function getNameFromLine($line) { if (preg_match("/.*-(.*)\s\d+/", 阅读全文

posted @ 2013-07-07 16:48 mtima 阅读(263) 评论(0) 推荐(0)

pubsub模式

摘要: subscribe('book', function() { var_dump(func_get_args()); echo "I want to read book!";});$pubSuber->publish('book', "this is an string.");$pubSuber->unsubscribe($token);$pubSuber->publish('book', 'suxiaolin');/** * 实现pubsub模式 * 来自> * @a 阅读全文

posted @ 2013-07-07 16:11 mtima 阅读(393) 评论(0) 推荐(0)

导航