Can you make an object 'callable'?

前端 未结 4 546
粉色の甜心
粉色の甜心 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 05:17

    Others have provided the current answer ("no") and some workarounds. As far as first-class support in the future, I suggested this very thing to the es-discuss mailing list. The idea did not get very far that time around, but perhaps some additional interest would help get the idea moving again.

    https://esdiscuss.org/topic/proposal-default-object-method

提交回复
热议问题