UNPKG

callable-instance2

Version:

Instances of classes which are directly callable as functions.

41 lines (32 loc) 954 B
// @ts-nocheck function CallableInstance(property) { // @ts-ignore const self = this; // @ts-ignore const func = this.constructor.prototype[property]; const apply = function () { return func.apply(apply, arguments); }; // @ts-ignore Object.setPrototypeOf(apply, this.constructor.prototype); Object.getOwnPropertyNames(func) .forEach(function (p) { Object.defineProperty(apply, p, Object.getOwnPropertyDescriptor(func, p)); }) ; return apply; } CallableInstance.prototype = Object.create(Function.prototype); export { CallableInstance }; export default CallableInstance; // @ts-ignore if (process.env.TSDX_FORMAT !== 'esm') { Object.defineProperty(CallableInstance, "__esModule", { value: true }); Object.defineProperty(CallableInstance, 'CallableInstance', { value: CallableInstance }); Object.defineProperty(CallableInstance, 'default', { value: CallableInstance }); } //module.exports = Object.freeze(module.exports);