上一页 1 2 3 4 5 6 7 ··· 10 下一页

2013年7月8日

observer模式

摘要: =5.3 * 整理: 苏小林 */class Newspaper implements \SplSubject{ private $name; private $observers = array(); private $content; public function __construct($name) { $this->name = $name; } //添加一个观察者 public function attach(\SplObserver $observer) { $this->observers[] = $... 阅读全文

posted @ 2013-07-08 15:34 mtima 阅读(140) 评论(0) 推荐(0) 编辑

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 阅读(181) 评论(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 阅读(326) 评论(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 阅读(424) 评论(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 阅读(229) 评论(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 阅读(369) 评论(0) 推荐(0) 编辑

2013年6月12日

双向循环链表

摘要: <?phpclass double_link { public $name; public $next; public $prev; public function __construct($name) { $this->name = $name; }}function get_double_link($total) { $current = $first = new double_link(1); $pre = NULL; for ($i=2; $i < $total; $i++) { $current -> ne... 阅读全文

posted @ 2013-06-12 18:32 mtima 阅读(154) 评论(0) 推荐(0) 编辑

2013年6月8日

实用的任选n算法

摘要: $arr = array(1,2,3,4,5,6)需求从$arr中选出任意多个元素的所有组合比如任选三,通常我们只需要用三个for循环,但是这并不能适合于所有情况,如果在要求得出所有任选四的所有组合,就必须再加四个for循环,如果再多呢?适用于任选n的所有情况:<?php//核心:采用堆+递归的形式实现function get_rx($target,$arr) { static $rzRzt = array(); $count = count($arr); $selfName = __FUNCTION__; global $n; if ($count<1)... 阅读全文

posted @ 2013-06-08 09:52 mtima 阅读(211) 评论(0) 推荐(0) 编辑

二维组合连乘相加

摘要: function award_sp_cal($spRzt) { $totalAward = 1; $temp = null; foreach($spRzt as $sp) { if (count($sp) == 1) { $totalAward *= array_shift($sp); } else if (count($sp) >1 ) { $temp = $totalAward; $totalAward = 0;//原理: a*x + b*x = (a+b)*x ... 阅读全文

posted @ 2013-06-08 09:35 mtima 阅读(158) 评论(0) 推荐(0) 编辑

2013年5月23日

js模块化

摘要: 在js中借助匿名函数实现功能的模块化下面实现一个计算器模块计算器得有 加(add) 减() 乘(multi) 除(diliver) 的功能,并且它们应该以 xx.add(1,2)的形式调用废话不多说,上代码var cal = (function() { return { 'add':function(a,b) { return a+b; }, 'multi':function(a,b) { return a*b; } };})();console.log(cal.add(1,2));... 阅读全文

posted @ 2013-05-23 22:54 mtima 阅读(195) 评论(0) 推荐(0) 编辑

上一页 1 2 3 4 5 6 7 ··· 10 下一页

导航