[英]“:” operator in Javascript
I'm using project polymer https://www.polymer-project.org/ and trying to precompile some Webcomponents in a Rails app. 我正在使用项目聚合物https://www.polymer-project.org/并尝试在Rails应用程序中预编译一些Web组件。
I get an error in the file: 我在文件中收到错误:
https://polymer-topeka.appspot.com/components/firebase/firebase.js https://polymer-topeka.appspot.com/components/firebase/firebase.js
So I guess it is malformed. 因此,我认为它格式错误。
After I decompressed it with http://jsbeautifier.org/ I tried to use jstocoffee to check what could be a syntax error: 用http://jsbeautifier.org/解压缩后,我尝试使用jstocoffee检查可能是语法错误的内容:
http://js2coffee.org/ http://js2coffee.org/
And found this: 并发现了这一点:
function Ua(a, b) {
return a > b ? 1 : a < b ? -1 : 0
}
var Va;
a: {
var Wa = aa.navigator;
if (Wa) {
var Xa = Wa.userAgent;
if (Xa) {
Va = Xa;
break a
}
}
Va = ""
}
What does the "a:" mean? “ a:”是什么意思? Because js2coffee sends an error right there.
因为js2coffee在那里立即发送错误。 It is a valid operator?
这是一个有效的运算符?
The a:
in your code is a label. 代码中的
a:
是标签。 JavaScript labels work with break
and continue
statements as a (somewhat limited) form of "go to". JavaScript标签与
break
和continue
语句一起使用(某种程度上受限制)“转到”形式。
Thus this code: 因此这段代码:
a: {
var Wa = aa.navigator;
if (Wa) {
var Xa = Wa.userAgent;
if (Xa) {
Va = Xa;
break a
}
}
Va = ""
}
works as if it had been written: 就像写的一样工作:
var var Wa = aa.navigator;
if (Wa && (Xa = Wa.userAgent) {
Va = Xa;
}
else {
Va = "";
}
So Va
gets set to the empty string if the code can't find both the navigator
and navigator.userAgent
values. 因此,如果代码无法同时找到
navigator
和navigator.userAgent
值,则Va
设置为空字符串。
In the function 在功能上
function Ua(a, b) {
return a > b ? 1 : a < b ? -1 : 0
}
Says: if a is greater than b then return 1; 说:如果a大于b,则返回1;否则,返回1。 else if a is less than b return -1;
否则,如果a小于b,则返回-1;否则,返回-1。 else return 0.
否则返回0。
the other a statement 另一个声明
a: {
is a global variable. 是全局变量。 It doesn't have anything to do with the function.
它与功能无关。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.