色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

dess中一個簡單的多路委托的實現

復制代碼 代碼如下:
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事件派發。

JavaScript技術dess中一個簡單的多路委托的實現,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 六安市| 巴南区| 安顺市| 白朗县| 青川县| 宁德市| 辽阳县| 河南省| 海盐县| 钟山县| 黄陵县| 且末县| 北碚区| 新野县| 建始县| 靖宇县| 乃东县| 阜康市| 通州区| 大方县| 合川市| 西昌市| 扎兰屯市| 航空| 兴国县| 吉林市| 栾城县| 旬邑县| 阿克苏市| 天等县| 托克托县| 应城市| 河曲县| 大洼县| 石家庄市| 营口市| 连平县| 定边县| 通化县| 清镇市| 旬阳县|