'::'(双冒号)在 JavaScript 中有什么作用? [英] What does ‘::’ (double colon) do in JavaScript?
问题描述
一些 JavaScript API 的文档显示了以下片段作为如何调用某些函数的示例:
<button type="button" onClick="foo.DoIt(42342::37438)">点击</button>
::
显然在这里用于允许将一个或两个参数传递给函数.
::
在 JavaScript 中有什么作用?
函数如何知道是否传递了一两个值?它是如何读取它们的?
<小时>仔细观察,这些例子展示了其他奇怪的东西,比如
<button type="button" onClick="foo.Qux(425;1,34::)">点击</button>
至少 //
看起来是错误的.
所以我想这不是我不知道的一些花哨的新语法,但也许这些示例只是缺少单个字符串参数周围的引号.
没什么.这是一个语法错误.
<预><代码>>>>警报(42342::37438)SyntaxError: 缺少 ) 参数列表后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.
Nothing. It is a syntax error.
>>> alert(42342::37438)
SyntaxError: missing ) after argument list
这篇关于'::'(双冒号)在 JavaScript 中有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!