JavaScript中的'::'(双冒号)有什么作用? [英] What does ‘::’ (double colon) do in JavaScript?

查看:558
本文介绍了JavaScript中的'::'(双冒号)有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

某些JavaScript API的文档显示以下代码段作为如何调用某些函数的示例:

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.

在JavaScript中做什么 ::

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>

至少 // 看起来错了。

所以我猜这不是一些我不知道的新奇语法,但也许这些例子只是缺少一个字符串参数的引号。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆