bind vs. call vs. wrapper

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
call
class Foo {
  foo() {
    return 'foo';
  }
  bar() {
    return this.foo();
  }
}
const foo = new Foo();
const fun = foo.bar;
console.assert(fun.call(foo) === 'foo', 'did not work');
ready
wrapper
class Foo {
  foo() {
    return 'foo';
  }
  bar() {
    return this.foo();
  }
}
const foo = new Foo();
const fun = () => foo.bar();
console.assert(fun() === 'foo', 'did not work');
ready
bind
class Foo {
  foo() {
    return 'foo';
  }
  bar() {
    return this.foo();
  }
}
const foo = new Foo();
const fun = foo.bar.bind(foo);
console.assert(fun() === 'foo', 'did not work');
ready

Revisions

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