I know this may be a bizarre question with possibly no practical application, but would it be possible to make a JavaScript class that constructs instances that behave as functions? Here's what I mean:
function Factory() {}
// this may not be necessary, but I'll include it for sake of clarification
Factory.prototype = Object.create(Function.prototype);
var method = new Factory();
method(); // Objective: should not throw TypeError
To further clarify the objective:
methodshould be callable as a functionmethodshould be the result of calling a constructor (e.g.var method = new Factory()in this case)- The constructor cannot be
Function.
methodable to be called as a function, and have it as the result of calling a constructor that's notFunction.