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

前端 未结 6 1643
攒了一身酷
攒了一身酷 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

    As mentioned in this answer of What does ‘::’ (double colon) do in javascript?

    :: is a ES2016 operator that is shorthand for bind. This answer intends to assist those that have encountered :: since the ES2016 spec, however, does not apply to the context in which this question was asked.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-07 02:17

    This is an extension to the Javascript language implemented by Microsoft. It's purpose is to specify an event handler for a COM object referenced on the page. SpeechMikeControl is the globally-scoped name of the COM (and/or ActiveX) object:

    • either with an OBJECT or some other element, which has an id property of SpeechMikeControl, or
    • a global variable SpeechMikeControl declared somewhere previously in the Javascript

    SPMEventButton is the name of the COM event which will be raised by the SpeechMikeControl object under who-knows-what circumstances.

    The double colon is an instruction to connect the function body as a handler to the control's event.

    0 讨论(0)
  • 2020-12-07 02:20

    I'm pretty certain that's not valid Javascript syntax.

    If it works in IE but not other browsers, it could possibly be that IE is treating it as another scripting language (maybe VBScript? although I don't recall that having a double colon operator either? Not sure what other language it could be though.)

    0 讨论(0)
  • 2020-12-07 02:21

    I've been able to find an obscure reference in some scanned manual from Microsoft Office Infopath 2003. It appears to be a JScript syntax:

    a double colon is used as separator between the script ID and the event name

    My guess is that's not part (or no longer part) of Internet explorer's ECMAScript implementation but it belongs (or used to belong) to Microsoft Office's implementation.

    0 讨论(0)
  • 2020-12-07 02:27

    Pretty sure it's a syntax error

    0 讨论(0)
提交回复
热议问题