Copy codeThe Code is as follows:
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 );
}
This SDelegate may be quite strange to use. For example, many operations must be re-assigned. In Dess, SDelegate is mainly used for some specific occasions, such as DOM Event distribution.