8

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

<SCRIPT LANGUAGE=javascript> 

     function SpeechMikeControl::SPMEventButton(lDeviceID, EventId) {
        alert("lDeviceID=" + lDeviceID + ", EventId=" + EventId);
     }

</SCRIPT>

double colon? This is from using a philips speech mike from a web page.

Any idea what this double colon means? It seems like a syntax error to me but it works! (at least in IE).

Zev Spitz
  • 13,950
  • 6
  • 64
  • 136
sproketboy
  • 8,967
  • 18
  • 65
  • 95

6 Answers6

7

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.

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
  • Thanks. That seems right. I guess IE is falling back on JScript when it sees this construct. – sproketboy Apr 19 '11 at 11:48
  • 1
    A more relevant reference would be to [Scripting Events](https://msdn.microsoft.com/en-us/library/ms974564.aspx), where this syntax is as described in [this](http://stackoverflow.com/a/7196576/111794) answer. – Zev Spitz Feb 01 '17 at 21:47
6

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.

Zev Spitz
  • 13,950
  • 6
  • 64
  • 136
richard
  • 61
  • 1
  • 1
3

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.

Community
  • 1
  • 1
Dmase05
  • 1,059
  • 15
  • 18
  • The question was asked in 2011. – Guy Waldman Sep 10 '16 at 16:48
  • 3
    Yes, this question likely comes up in search engine results quite often now that ES2016 is here and uses `::`. As I mentioned above, this answer does not refer to the original question but intends to inform those looking for the ES2016 implementation. – Dmase05 Oct 07 '16 at 00:27
  • The answer has no real bearing on the question, because the syntax in the question is a function declaration, and cannot possibly have anything to do with ES2016 binding. – Zev Spitz Feb 01 '17 at 21:57
  • 2
    I appreciate this answer, as I was searching for what `::` does in regards to ES2016. Searching for "what does :: do" is difficult, as `::` isn't very search friendly, so again, I find value in this answer. – Kevin Lamping Feb 27 '19 at 19:40
3

Pretty sure it's a syntax error

Mild Fuzz
  • 29,463
  • 31
  • 100
  • 148
  • @Dan it doesn't work. You're just not seeing the error for some reason. Maybe IE is hiding them - look out for the yellow exclamation mark in the bottom left corner in IE8 – Pekka Apr 19 '11 at 11:02
  • It is a syntax error only to the beholder. While searching for some answers, it seems it is indeed JScript syntax... – Christian Nov 07 '11 at 23:29
  • 1
    It is not a syntax error under IE. See [Scripting Events](https://msdn.microsoft.com/en-us/library/ms974564.aspx), [here](http://stackoverflow.com/questions/41713117/acitvex-event-handlers-in-an-hta-using-javascript), and the answer [here](http://stackoverflow.com/a/7196576/111794). – Zev Spitz Feb 01 '17 at 22:01
0

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.)

Spudley
  • 166,037
  • 39
  • 233
  • 307
  • IE runs JScript, not "standard" Javascript hence it recognizes more things than you'd think :) – Christian Nov 07 '11 at 23:31
  • It does indeed have special meaning in Javascript under IE and WSH. See [Scripting Events](https://msdn.microsoft.com/en-us/library/ms974564.aspx), [here](http://stackoverflow.com/questions/41713117/acitvex-event-handlers-in-an-hta-using-javascript), and the answer [here](http://stackoverflow.com/a/7196576/111794). – Zev Spitz Feb 01 '17 at 22:03
0

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.

Community
  • 1
  • 1
RobG
  • 142,382
  • 31
  • 172
  • 209
  • 1
    It is not a syntax error under IE. See [Scripting Events](https://msdn.microsoft.com/en-us/library/ms974564.aspx), [here](http://stackoverflow.com/questions/41713117/acitvex-event-handlers-in-an-hta-using-javascript), and the answer [here](http://stackoverflow.com/a/7196576/111794). – Zev Spitz Feb 01 '17 at 22:02
  • @ZevSpitz—the question is tagged javascript, not JScript. It would be more helpful if you posted an answer with versions of JScript that support it and the relevant versions of IE, as well as whether it's supported by Microsoft Edge. – RobG Feb 01 '17 at 23:08
  • 1
    _the question is tagged javascript, not JScript_ Well, that's easily fixed. :) But, I misspoke; it's valid under Microsoft JScript (AFAIK all versions) which can be used in multiple environments -- IE, WSH, classic ASP. – Zev Spitz Feb 02 '17 at 06:22