开发者

Question about cache in javascript/jquery

I wonder if selector "$cacheA" will be cached on page load in the example below?

// MY JQUERY FUNCTION/PLUGIN
(function( $ ){
$.fn.myFunction = function() {

var $cacheA = this,
$cacheB = $cacheA.children(),
$cacheC = $cacheB.eq(0);
$cacheD = $cacheA.parent();    

$cacheD.click开发者_C百科(function(){

$cacheA.toggle();
$cacheB.fadeIn();
$cacheC.slideUp();

});

};
})( jQuery );
// END JQUERY FUNCTION/PLUGIN



$(window).load(function(){

$('#mySelector').myFunction();

});

Would it be any reason to do this:

$(window).load(function(){

var $mySelector = $('#mySelector');

$mySelector.myFunction();

});


If, inside your "load" handler, you were to do many jQuery operations with "$mySelector", then saving that in a variable would be a good idea. However, in your example, you only use the value once, so it really makes no difference at all.


Firstable, $cacheA and others inside click function will be undefined.

$cacheD.click(function(){

$cacheA.toggle();
$cacheB.fadeIn();
$cacheC.slideUp();

});

Second,

$.fn.myFunction = function() {

var $cacheA = this,
$cacheB = $cacheA.children(),
$cacheC = $cacheB.eq(0);
$cacheD = $cacheA.parent();
}

So, after $('selector').myFunction() how can I use $cacheB, $cacheC and $cacheD? Where they are will store?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜