What does ‘::’ (double colon) do in javascript for events?

前端 未结 6 1659
攒了一身酷
攒了一身酷 2020-12-07 01:33

I saw this code and I\'m scratching my head trying to decide how it works.



        
6条回答
  •  既然无缘
    2020-12-07 02:10

    The question may not be a duplicate of What does ‘::’ (double colon) do in javascript?, but the answer is: it is a syntax error.

    In the following:

    function SpeechMikeControl::SPMEventButton(lDeviceID, EventId) {
    

    the keyword function in the global context at the start of an expression indicates a function declaration. Following must be an identifier that is the function name. After the name must be an opening grouping operator '(', formal parameter list and closing grouping operator ')'. So between function and () can only be a single identifier of allowable characters (that isn't a reserved word, or future reserved word, but that isn't an issue here).

    The ":" (colon) character is a punctuator and can not appear in an identifier. So it must cause a syntax error if the code is treated as javascript.

    Perhaps IE has an extension to the language, I don't know ECMAScript well enough to know if that is permissible, but I'd expect not since it will break other implementations.

提交回复
热议问题