Tag: 这一点

是否使用$ this而不是$(this)提供性能增强?

假设我有以下例子: 例子一 $('.my_Selector_Selected_More_Than_One_Element').each(function() { $(this).stuff(); $(this).moreStuff(); $(this).otherStuff(); $(this).herStuff(); $(this).myStuff(); $(this).theirStuff(); $(this).children().each(function(){ howMuchStuff(); }); $(this).tooMuchStuff(); // Plus just some regular stuff $(this).css('display','none'); $(this).css('font-weight','bold'); $(this).has('.hisBabiesStuff').css('color','light blue'); $(this).has('.herBabiesStuff').css('color','pink'); } 现在,可能是: 例二 $('.my_Selector_Selected_More_Than_One_Element').each(function() { $this = $(this); $this.stuff(); $this.moreStuff(); $this.otherStuff(); $this.herStuff(); $this.myStuff(); $this.theirStuff(); $this.children().each(function(){ howMuchStuff(); }); $this.tooMuchStuff(); // Plus just some regular stuff $this.css('display','none'); $this.css('font-weight','bold'); $this.has('.hisBabiesStuff').css('color','light blue'); $this.has('.herBabiesStuff').css('color','pink'); } […]