Binding Scope vs Private Scope

JavaScript performance comparison

Revision 3 of this test case created by Prannay

Preparation code

<script>

  
  var ClassA = function(state) {
    this._x = {p : 5};
    this.f = function() { return Math.round(this._x['p']*9192631770.36507) % 299792; };
  };

  var ClassB = function(state) {
    this._x = {p : 5};
    var that = this;
    this.f = function() { return Math.round(that._x['p']*9192631770.36507) % 299792; };
  };
  
  var instA = new ClassA('foo');
  var instB = new ClassB('foo');
</script>
    

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Bind
var f = instA.f;
var result = f.apply(instA,[]);
pending…
Private scope
var f = instB.f;
var result = f();
pending…

Compare results of other browsers

Revisions

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

0 Comments