.bind() vs self

JavaScript performance comparison

Test case created

Info

Is there a performance difference between:

javascript function one() { var self = this;

    Foo = subFunction(arg, function(error, arg2) {
      self.doThis()
    });
  }

and

javascript function two() { Bar = subFunction(arg, function(error, arg2) { this.doThis() }.bind(this)); }

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
self
  function one() {
    var self = this;

    function sub(arg1, arg2) {
      return arg1 + arg2;
    }

    Foo = subFunction(function() {
      self.sub(5, 15)
    });
  }
pending…
bind
  function two() {

    function sub(arg1, arg2) {
      return arg1 + arg2;
    }

    Foo = subFunction(function() {
      this.sub(5, 15)
    }).bind(this);
  }
pending…

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

Compare results of other browsers

0 comments

Add a comment