this VS $.proxy

Benchmark created by jeremy on


Preparation HTML

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

Test runner

Ready to run.

Testing in
TestOps/sec
this
var obj = {
  e: null,
  construct: function() {
    this.e = $('#foo');
    var that = this;
    setTimeout(function() {
      that.callBack(that);
    }, 1);
  },
  callBack: function(t) {
    console.log(t.t);
  }
}

obj.construct();
ready
proxy
var obj = {
  e: null,
  construct: function() {
    this.e = $('#foo');
    var that = this;
    setTimeout($.proxy(that.callBack, that), 1);
  },
  callBack: function(t) {
    console.log(this.t);
  }
}
obj.construct();
ready

Revisions

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

  • Revision 1: published by jeremy on