Is typeof foo === 'function'
the only way (other than attempting to call the object) to determine whether an object is callable?
If so, is this because it is otherwise impossible to distinguish between a callable object and an object that merely inherits from Function.prototype
?
I note that until ES2015, the only way (other than supplying a string to Function
, and possibly eval
) to create a callable object, was to use the function () {}
syntax, to create a function-object directly; and that ES2015 introduced a way of extending exotic objects like Function
, enabling callable objects to be configured using the class CallableClass extends Function
syntax, and instantiated using the new CallableClass
syntax.
To restate: For all objects, typeof
returns 'object'
EXCEPT for callable function-objects, for which it returns 'function'
. Is this the singular language feature, deliberately included, to enable userland identification of callable objects (because there was no other way)?