$(this) vs var xxx = $(this)

Benchmark created by Arthur on


Description

What is faster: $(this).xxx(); $(this).yyy(); or var _this = $(this); _this.xxx(); _this.yyy();

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id="some_div"></div>

Test runner

Ready to run.

Testing in
TestOps/sec
$(this)
$('#some_div').each(function(){
  $(this).hide();
  $(this).show();
});
ready
var _this = $(this)
$('#some_div').each(function(){
  var _this = $(this);
  _this.hide();
  _this.show();
});
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by Arthur on