Can you make an object 'callable'?

前端 未结 4 577
粉色の甜心
粉色の甜心 2020-12-03 04:37

Is it possible to make an object callable by implementing either call or apply on it, or in some other way? E.g.:

var obj = {};
obj         


        
4条回答
  •  孤街浪徒
    2020-12-03 04:58

    ES6 has better solution for this now. If you create your objects in a different way (using class, extending 'Function' type), you can have a callable instance of it.

    See also: How to extend Function with ES6 classes?

提交回复
热议问题