bind vs. call vs. wrapper (v2)

Revision 2 of this benchmark created on


Setup

class Foo {
  foo() {
    return 'foo';
  }
  bar() {
    return this.foo();
  }
}

Test runner

Ready to run.

Testing in
TestOps/sec
call
const foo = new Foo();
const fun = foo.bar;
console.assert(fun.call(foo) === 'foo', 'did not work');
ready
wrapper
const foo = new Foo();
const fun = () => foo.bar();
console.assert(fun() === 'foo', 'did not work');
ready
bind
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.