Can I apply this functionality to any object?"
No. As of ECMAScript 10th Edition (2019) this is not possible.
The ()-operator/expression construct can only be used on function objects.
This is because it uses the [[Call]] internal method. Section 7.3.12 Call indicates this is only defined for function objects and the specification makes no provision to add the [[Call]] internal method to other objects.
7.3.12 Call ( F, V [ , argumentsList ] )
The abstract operation Call is used to call the [[Call]] internal method of a function object. [..]
The specification is written in such a way that a future revision might add generalized support.
Anyway, as shown in the question, function objects can be mutated as a proxy: so carry on, flavoring as desired.
- 62.5k
- 15
- 159
- 234