手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >dess中一个简单的多路委托的实现
dess中一个简单的多路委托的实现
摘要:复制代码代码如下:varSDelegate=function(f,b,c){if(b){this.asFunction_=function(...

复制代码 代码如下:

var SDelegate = function(f, b, c) {

if (b) {

this.asFunction_ = function() {

return f.apply(b, arguments);

}

} else {

this.asFunction_ = function() {

return f.apply(this, arguments);

}

}

this.method_ = f;

this.binding_ = b;

this.continus = c;

}

SDelegate.composite = function(d) {

if (d.continus) {

var con = d.continus.composited_ = SDelegate.composite(d.continus);

var method = d.asFunction_;

return function() {

con.apply(this, arguments);

return method.apply(this, arguments);

}

} else {

return d.asFunction_;

}

}

SDelegate.prototype.call = function() {

if (!this.composited_) this.composited_ = SDelegate.composite(this);

return this.composited_.apply(arguments[0], Array.prototype.slice.call(arguments, 1));

}

SDelegate.prototype.remove = function() {

var removeP = function(parent, item, test, data) {

if (!item) return;

parent.composited_ = item.composited_ = null;

if (test(item, data)) {

parent.continus = item.continus;

removeP(parent, item.continus, test, data);

} else {

removeP(item, item.continus, test, data);

}

};

return function(test, data) {

var p = this;

if (test(this, data)) {

p = this.continus;

}

removeP(p, p.continus, test, data);

p.composited_ = null;

return p;

}

}();

SDelegate.prototype.append = function(f, b) {

return new SDelegate(f, b, this);

}

这个SDelegate用起来可能会比较诡异,比如很多操作都要重新赋值。Dess中,SDelegate主要用于一些特定场合,如DOM事件派发。

【dess中一个简单的多路委托的实现】相关文章:

一个很简单的办法实现TD的加亮效果.

js实现简单锁屏功能实例

javascript实现带下拉子菜单的导航菜单效果

总结一些js自定义的函数

简单介绍JavaScript的变量和数据类型

IE中jscript/javascript的条件编译

一个很Cool的JS菜单效果

jQuery插件expander实现图片翻转特效

jQuery插件zepto.js简单实现tab切换

一个很简单的办法实现TD的加亮效果.

精品推荐
分类导航