I will write my answer assuming that you were after __call__
functionality available in Python and often referred to as "callable object". "Callable object" sounds foreign in JavaScript context.
I've tried several JavaScript engines, but none of those I've tried allows you to call objects, even if you inherit from Function
. For instance:
function Callable(x) {
... "use strict";
... this.__proto__ = Function.prototype;
... this.toString = function() { return x; };
... }
undefined
> var c = new Callable(42);
var c = new Callable(42);
undefined
> c;
c;
{ toString: [function] }
> c(42);
c(42);
TypeError: Property 'c' of object #
This is V8 (Node.js). I.e. you may have an object, that formally inherits from function, but it is not callable, and I could not find a way to convince the runtime it may be called. I had similar results in Mozilla's implementation of JavaScrip, so I think it must be universal.
However, the role of custom types in JavaScript is vanishingly small, so I don't think you will be missing it that much anyway. But, as you had already discovered, you can create properties on functions, the same way as you can on objects. So, you can do it, just in a less convenient way.