Run details:
Mozilla/5.0 (Android 11; Mobile; rv:100.0) Gecko/100.0 Firefox/100.0
Firefox Mobile 100
Android
Mobile
2 years ago
Test name Executions per second
Closure plus class check 39525.8 Ops/sec
Function apply 36903.6 Ops/sec
Tests:
  • Closure plus class check

    x
     
    class Foo {}
    class Bar extends Foo {
      add(a, b) {
        return a + b;
      }
    }
    function apply(ctor, impl, op) {
      if (impl instanceof ctor) {
        return op(impl);
      }
    }
    const bar = new Bar();
    apply(Bar, bar, impl => impl.add(3, 5));
  • Function apply

     
    class Foo {}
    class Bar extends Foo {
      add(a, b) {
        return a + b;
      }
    }
    const bar = new Bar();
    const fn = bar['add'];
    if (fn) {
      return fn.apply(bar, [3, 5]);
    }