{
if(this.xml.readyState!=4)return;//not ready
if(this.xml.parseError.errorCode)
myalert(this.name this.xml.parseError.reason);
else
myalert(this.xml.xml);
}
---------------2002.3.8:-------------
function FunctionSelf(){return FunctionSelf.caller;}
function Delegate(obj,funcOrName)
{
var delegate=new Function("","return FunctionSelf().Invoke(FunctionSelf().arguments)");
delegate.Arguments=new Array();
delegate.Object=obj;
delegate.UniqueName="DelegateUniqueID" Math.floor((new Date().getTime() Math.random())*1000);
if(typeof(funcOrName)=="string")
{
delegate.FuncName=funcOrName;
delegate.Function=obj[delegate.FuncName];
}
else
{
delegate.FuncName=null;
delegate.Function=funcOrName;
}
delegate.Invoke=Delegate.Invoke;
delegate.Detach=Delegate.Detach;
delegate.SetArguments=Delegate.SetArguments;
delegate.PreInvoke=Delegate.PreInvoke;
delegate.valueOf=new Function("","return \"" delegate.UniqueName "\"");
delegate.toString=new Function("","return \"" delegate.UniqueName "\"");
return delegate;
}
function Delegate.GetCaller()
{
var cid=FunctionSelf().caller.caller.CallID;
return Delegate.Coll[cid];
}
function Delegate.GetDelegate()
{
var cid=FunctionSelf().caller.caller.CallID;
return Delegate.Coll[cid].Delegate;
}
function Delegate.PreInvoke()
{
this.SetArguments(Delegate.PreInvoke.arguments);
return this;
}
function Delegate.SetArguments(args)
{
if(args==null)args=new Array();
this.Arguments=new Array();
for(var i=0;i<args.length;i )this.Arguments[i]=args[i];
return this;
}
function Delegate.Invoke(args)
{
if(this.Object==null)return;
var cid=Delegate.Coll.Insert(this,args);
var strArguments="";
var i=0;
for(i=0;i<args.length;i )
{
strArguments ="Delegate.Coll[''''" cid "''''].Arguments[" i "]";
if(i<args.length-1)strArguments =",";
}
if(i>0&&i<this.Arguments.length)strArguments =",";
for(;i<this.Arguments.length;i )
{
strArguments ="Delegate.Coll[''''" cid "''''].Delegate.Arguments[" i "]";
if(i<this.Arguments.length-1)strArguments =",";
}
var funcName=this.FuncName||cid;
if(this.FuncName==null)this.Object[funcName]=this.Function;
var res;
var exception;
try
{
res=eval("new Function('''''''',\"FunctionSelf().CallID=''''" cid "'''';return Delegate.Coll[''''" cid "''''].Delegate.Object[''''" funcName "''''](" strArguments ")\")()");
}catch(x){exception=x}
if(this.Object&&(this.FuncName==null))delete this.Object[funcName];
Delegate.Coll.Remove(cid);
if(exception)throw(exception);
return res;
}
function Delegate.Detach()
{
this.Object=null;
this.Function=null;
this.FuncName=null;
this.UniqueName=null;
}
function Delegate.EvalCaller(delegate,args,cid)
{
this.Delegate=delegate;
this.Arguments=args;
this.CallID=cid;
}
function Delegate.Coll(){}
function Delegate.Coll.Insert(delegate,args)
{
if(typeof(Delegate.Coll.Length)=="undefined")Delegate.Coll.Length=0;
Delegate.Coll.Length ;
var cid=delegate.UniqueName "call" Math.floor((new Date().getTime() Math.random())*1000);
var EvalCaller=new Delegate.EvalCaller(delegate,args,cid);
Delegate.Coll[cid]=EvalCaller;
return cid;
}
function Delegate.Coll.Remove(cid)
{
delete Delegate.Coll[cid];
Delegate.Coll.Length--;
}
--------------------例子:
function myjoin()
{
var str="";
for(var i=0;i<myjoin.arguments.length;i )
str =myjoin.arguments[i];
return str;
}
alert(
Delegate(new Object(),myjoin)
.PreInvoke(1,2,3,4,5,6,7,8,9)
.PreInvoke("a","b","c","d","e")
(9,8,7,6)
);
---------------
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




