Bind vs Self closure

JavaScript performance comparison

Revision 7 of this test case created

Preparation code

<script>
function test(){
 this.a = 0;
}
test.prototype.exec1 = function() {
var self = this;
 exec(function(){
self.foo();
})
};

test.prototype.exec2 = function(){
exec(function(){
this.foo();
}.bind(this));
}
test.prototype.foo = function(){
  this.a = 1;
  this.b=4;
};

var mine = new test();
var exec = function(fn) {
fn();
}

</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
binded
mine.exec2()
pending…
closured
mine.exec1()
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. Here’s a list of current revisions for this page:

0 comments

Add a comment