在这段代码中,触发器会调用topbar.resize还是仅仅运行其中包含的函数?我假设两者之间存在上下文差异,或者它是如何工作的?
jQuery.bind("hideBackstage", topbar.resize);
修改:如何只需调用topbar.resize即可实现?
答案 0 :(得分:1)
电话会议相当于
topbar.resize.call(touchedElement, jqueryWrappedEvent);
即topbar.resize
中的“包含”函数将使用接收者(this
)调用已接收事件的元素和参数事件(包装为jquery事件)。
这与
不同topbar.resize()
,因为
this
)不会是topbar
编辑后编辑:
如果您只是希望呼叫等同于topbar.resize()
,只需执行以下操作:
jQuery.bind("hideBackstage", function(){topbar.resize()});
答案 1 :(得分:0)
您可以使用jQuery代理或
jQuery.bind("hideBackstage", function(){
topbar.resize.apply(topbar, arguments); // seting context as topbar for resize.
});
答案 2 :(得分:0)
您可以使用$.proxy()
(有趣的是,类似于Function.prototype.bind()
)。
jQuery.bind("hideBackstage", $.proxy(topbar.resize, topbar));
但是,您无权访问event
对象。