admin管理员组文章数量:1134239
The documentation of some JavaScript APIs shows the following snippets as an example of 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?
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 examples are just missing quotes around a single string argument.
The documentation of some JavaScript APIs shows the following snippets as an example of 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?
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 examples are just missing quotes around a single string argument.
Share Improve this question edited May 18, 2017 at 17:45 Peter Mortensen 31.6k22 gold badges109 silver badges133 bronze badges asked Oct 5, 2009 at 14:14 dtbdtb 217k37 gold badges411 silver badges437 bronze badges 4- 1 AFAIK, that's a typo. The double-colon in that use makes no sense. – Robert K Commented Oct 5, 2009 at 14:19
- can you tell us more about the javascript API you are using.. – Xinus Commented Oct 5, 2009 at 14:24
- Sorry, the API and it's documentation are not publicly available, so I can't provide a link. – dtb Commented Oct 5, 2009 at 14:33
- see also JavaScript double colon (bind operator) – Aprillion Commented Aug 27, 2016 at 12:49
8 Answers
Reset to default 284It 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:
Nothing. It is a syntax error.
>>> alert(42342::37438)
SyntaxError: missing ) after argument list
::
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 the following?
$('this::is all one::parameter'); // jQuery selector
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!
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>
It could be using ECMAScript for XML (ECMA-357 standard) which would imply the double quotes are a XPath operator.
See ECMAScript for XML
I am guessing that the parameter list for foo.DoIt() is generated by code, and one the values was empty.
Perhaps it's a typo, and the whole thing is expected to be in quotes.
本文标签: syntaxWhat does ’ (double colon) do in JavaScriptStack Overflow
版权声明:本文标题:syntax - What does ‘::’ (double colon) do in JavaScript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736841695a1955128.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论