What does ‘::’ (double colon) do in JavaScript?

后端 未结 8 2284
深忆病人
深忆病人 2020-12-01 12:10

The documentation of some JavaScript APIs shows the following snippets as an example of how to invoke some function:

8条回答
  •  独厮守ぢ
    2020-12-01 12:46

    It was certainly not the case at the time of your question, but right now :: is a valid ES7 operator. It's actually a shortcut for bind.

    ::foo.bar
    

    is equivalent to

    foo.bar.bind(foo)
    

    See an explanation here for examples:

提交回复
热议问题