•Function.createDelegate(instance, method)方法:
–得到一个方法引用,执行它时则会调用method方法,并且保证method方法的上下文this引用为instance
•Function.createCallback(method, context)方法:
–得到一个方法引用,执行它时则会调用method方法,并将context作为额外的参数传入
aspx
<
form id
=
"
form1
"
runat
=
"
server
"
>
<
asp:ScriptManager ID
=
"
ScriptManager1
"
runat
=
"
server
"
/>
<
input type
=
"
button
"
value
=
"
Click Me
"
id
=
"
btn
"
/>
<
script language
=
"
javascript
"
type
=
"
text/javascript
"
>
var obj
=
{
text :
"
Hello
"
,
onClick : function(e, arg)
{
alert(
this
.text
+
"
"
+
arg);
}
}
//
obj.onClick();
//
$addHandler($get("btn"), "click", obj.onClick);
//
var onClickDelegate = Function.createDelegate(obj, obj.onClick);
var onClickDelegate
=
Function.createCallback(
Function.createDelegate(obj, obj.onClick),
"
World
"
);
$addHandler($
get
(
"
btn
"
),
"
click
"
, onClickDelegate);
</
script
>
</
form
>