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:
method
should be callable as a functionmethod
should be the result of calling a constructor (e.g.var method = new Factory()
in this case)- The constructor cannot be
Function
.