【发布时间】:2015-01-28 13:58:36
【问题描述】:
我有这个小代码:
ScenesController.prototype.viewAction = function() {
this.flash = this.di.HelperFlash.hasSupport();
this.$playerElem = !this.flash? $('#html_player') : $('#flash_player');
// the first click is just a sample, I need the same object in the Quailty Change method
$('.scenes_view_video_quailty').on('click', function() { echo($(this));});
$('.scenes_view_video_quailty').on('click', this.viewVideoQuailtyChange.bind(this));
};
ScenesController.prototype.viewVideoQuailtyChange = function(e) {
e.preventDefault();
if (!this.flash) {
echo(this);
echo($(this));
}
};
当我单击链接时,我需要将此变量传递给 QualityChange 方法 2。一个是对象(在绑定中),另一个是点击事件,因为我也需要点击的元素。
我正在尝试使用 .on('click', {$this: $(this)}, this.method) 解决方案,但不起作用,eventd.data.$this 看起来是一个不同的对象。
我需要与第一次单击方法中相同的对象。 (echo = console.log)
【问题讨论】:
-
只需在事件处理程序中使用
e.currentTarget来获取点击的元素。 -
哦,这是我当前问题的解决方案:D 但不是我问题的答案,我想在非匿名方法中拥有完整的对象。谢谢顺便说一句,好主意! :)
-
是的,我需要 QualityChange 方法中的完整 $(this),但它是不同的范围,这是 viewAction,但我想访问与匿名方法中相同的 this(我的示例中的第一个点击行)
标签: javascript jquery oop