“:”是什么意思? (冒号符号)在此 Javascript 代码“var switchToTarget : Transform;”上?
只是想知道下面这段 Javascript 代码中的“:”(冒号符号)是什么意思?
var switchToTarget : Transform;
谢谢, 吉诺
Just wondering what's the meaning of ":" (colon symbol) on this Javascript code below?
var switchToTarget : Transform;
Thanks,
Gino
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
编辑:阅读有关 Unity 的更多信息,他们创建了一个真正的自定义 为他们的脚本引擎实现 JavaScript(1),它是编译的并且有很多强类型功能,看起来像 ActionScript /ES4,但事实并非如此,该语言称为 UnityScript。
此实现使用冒号来表示标识符的类型,例如:
另请参阅:
您发布的代码不是有效的 ECMAScript 3(这是最广泛实施的标准),这只会给您一个
SyntaxError.
JavaScript 中的冒号只有几种用法:
对象文字语法:
条件运算符:
Case switch 语句的默认子句:
它可以出现在RegExp 文字上:
Edit: Reading more about Unity, they have created a really custom implementation of JavaScript(1) for their scripting engine, which is compiled and it has a lot of strongly typing features, it looks like ActionScript/ES4, but it isn't, the language is called UnityScript.
The colon is used by this implementation to denote the type of an identifier, e.g.:
See also:
The code you posted is not valid ECMAScript 3, (which is the most widely implemented standard), that will simply give you a
SyntaxError
.The colon symbol in JavaScript has only a few usages:
The object literal syntax:
The conditional operator:
Labeled statements:
Case and default clauses of the switch statement:
It can appear on RegExp literals:
它是 Adobe ActionScript,它是 javascript 的衍生版本。
var switchToTarget : 变换; // 声明 Transform 类型的 var switchToTarget。
var 你好: Text = new Text(); // 声明 Text 类型的 var hello 并初始化它。
http://www.adobe.com/livedocs/ flash/9.0/ActionScriptLangRefV3/flash/geom/Transform.html
It's Adobe ActionScript, which is a derivative of javascript.
var switchToTarget : Transform; // declare var switchToTarget of type Transform.
var hello : Text = new Text(); // declare var hello of type Text and initialize it.
http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/geom/Transform.html
我不确定它是否是标准 JavaScript 的一部分,但它声明了变量的类型。
在那种 JavaScript 风格中,这相当于几种强类型语言中的:
I'm not sure if it's part of standard JavaScript, but it declares the type of a variable.
in that flavor of JavaScript would be equivalent to this in several strongly-typed languages: