UNPKG

custom-function

Version:

Literally the only sane way, if not the fastest one, to extend the Function class without evaluation

16 lines (13 loc) 484 B
'use strict'; const {setPrototypeOf} = Object; /** * Given a `class Test extends CustomFunction {}` a `new Test(() => {})` * will returns the provided callback as `instanceof Test`. * @param {function} fn the callback that will inherit class methods. * @returns {function} the same, yet upgraded, `fn` callback. */ function CustomFunction(fn) { return setPrototypeOf(fn, new.target.prototype); } module.exports = CustomFunction CustomFunction.prototype = Function.prototype;