我正在处理代码snipet,我有这样的处理程序:
_ratingHandler = Function.createDelegate(this, this.onRatingChange);
_endClientCallBackHandler = Function.createDelegate(this, this.onEndClientCallBack);
我正在使用它们:
function attachEvent()
{
_eventOk = false;
_eventCallBackOk = false;
rating1Extender.add_Rated(_ratingHandler);
rating1Extender.add_EndClientCallback(_endClientCallBackHandler);
}
现在我想将此代码转换为Jquery。在jquery中createDelegate的替代方法是什么以及我将如何修改我的默认函数?
此致 Asif Hameed
答案 0 :(得分:0)
jQuery中Function.createDelegate函数的等价物是代理函数:
所以它可能看起来像这样:
_ratingHandler = $.proxy(this.onRatingChange, this);
_endClientCallBackHandler = $.proxy(this.onEndClientCallBack, this);
或者这也应该有效:
_ratingHandler = $.proxy(this, "onRatingChange");
_endClientCallBackHandler = $.proxy(this, "onEndClientCallBack");
我认为你不需要改变你的attachEvent方法,但是没有看到更多的代码,很难说。