Test name | Executions per second |
---|---|
Closure plus class check | 39525.8 Ops/sec |
Function apply | 36903.6 Ops/sec |
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));
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]);
}