is it legal to store jquery reference?
var global_ref = null;
function a(){
function some_click_handler {
glob开发者_JAVA百科al_ref = $(this);
}
}
// later in
function b()
{
$(global_ref).css(...) // or global_ref.css(...) ???
}
Is above concept right? and the syntax right?
You don't need $( global_ref )
, as global_ref
is already a jQuery object.
That being said, relying on globals like that is a bad practice, but it will work (assuming b()
is always called after a()
)
Ignoring some syntax errors this is certainly legal. But you just need global_ref.css(...)
as after global_ref = $(this)
it is already a reference to a jQuery object
精彩评论