Can I apply this functionality to any object?"
No. As of ECMAScript 10th Edition (2019) this is not possible.
The ()-operator can only be used on function objects.
This is because it uses the [[Call]] internal method, which only exists on functions. Section 7.3.12 Call indicates this is only defined for function objects:
The abstract operation Call is used to call the [[Call]] internal method of a function object..
However, as shown, Function-objects can be mutated to emulate such.
user2864740
- 62.5k
- 15
- 159
- 234