views:

663

answers:

6

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

<button type="button" onClick="foo.DoIt(72930)">Click</button>

<button type="button" onClick="foo.DoIt(42342::37438)">Click</button>

:: is obviously used here to allow either one or two arguments to be passed to the function.

What does :: do in JavaScript?

And how does the function know if one or two values were passed? How does it read them?


EDIT

On closer look, the examples show other weird stuff like

<button type="button" onClick="foo.Bar(72//893)">Click</button>

<button type="button" onClick="foo.Qux(425;1,34::)">Click</button>

At least the // looks just wrong. So I guess it's not some fancy new syntax that I'm not aware of but maybe the example are just missing quotes around a single string argument.

+7  A: 

Nothing. It is a syntax error.

>>> alert(42342::37438)
SyntaxError: missing ) after argument list
David Dorward
Yep, unless for some ungodly reason said developer is actually parsing the onclick attribute value with `document.getElementsByTagName('button')[0].getAttribute('onclick')` and extracting that information, that is an invalid ECMAScript expression.
meder
+2  A: 

In which example did you see that? So far, JavaScript does not have a double colon operator!

The double colon replaced the single-colon selectors for pseudo-elements in CSS3 to make an explicit distinction between pseudo-classes and pseudo-elements. But that is CSS3, not JavaScript! Not At ALL!

Tzury Bar Yochay
Given this, it sounds like perhaps he's looking at a jquery selector and omitted the quotes around the parameter.
Joel Coehoorn
probably. in any case, this question drew far more attention than I thought it would.
Tzury Bar Yochay
+2  A: 

Perhaps its a typo and the whole thing is expected to be in quotes.

Climber104
+6  A: 

'::' has nothing to do with the number of parameters. You can do that already in javascript with a normal comma:

function SomeFunction(param1, param2) {
   //...
}

SomeFunction('oneParam'); //perfectly legal

Also, based on Tzury Bar Yochay's answer, are you sure you're not looking at something like this:

$('this::is all one::parameter');  //jQuery selector
Joel Coehoorn
I guess you're right and it's missing the quotes. I will submit a bug report to the author :)
dtb
A: 

I am guessing that the parameter list for foo.DoIt() is generated by code, and one the values was empty.

RedFilter
+2  A: 

It must be a typo for

<button type="button" onClick="foo.DoIt('72930')">Click</button>

<button type="button" onClick="foo.DoIt('42342::37438')">Click</button>
Xinus