【发布时间】:2012-02-01 14:22:27
【问题描述】:
我在开发中使用 OOP 和 jQuery。
我曾经将我当前的对象 this 传递给像这样的 jQuery 函数:
$(myElement).live('click', this, function(el){
// I can access to my JS object using el.data
});
但我找不到如何使用 jQuery 函数 .queue() 做类似的事情。
有可能吗?
编辑
我给你我想使用.queue()的上下文:
CAPTIVEA.widget.Message = {
/**
* Displays generated message on the screen
* @method display
* @public
*/
display: function() {
// Display Message
$('.message')[this.effects.show](this.effects.duration, function(){
$(this).show();
$('.message span').show();
$('.message').children().show();
});
if (this.autoHide)
{ // Remove message after delay
$('.message').data('objMessage', this);
$('.message').delay(3000).queue(function(el){
$(this).data('objMessage').close();
});
}
},
/**
* Removes generated message from the screen
* @method close
* @public
*/
close: function() {
$('.message')[this.effects.hide](this.effects.duration, function(){
$(this).remove();
});
}
};
【问题讨论】:
-
你的意思是像
$(myElement).queue(function(el){});?因为这是可能的...... -
this在你的代码中代表什么类型的对象? -
@am not i am :它是对象文字。我给你的代码示例在这个对象的一个方法中
-
你如何使用
.queue()。该方法只对碰巧从中调用它的任何 jQuery 对象进行操作。您是否需要与特定元素或元素集相关联的数据?如果有,你考虑过$.data()吗? -
@am not i am : 我已经编辑了我的帖子以提供背景信息。
标签: javascript jquery oop