AS3 / JavaScript if语句逗号而不是& &安培; [英] AS3/JavaScript if statement commas instead of & &
问题描述
这在ActionScript 3和JavaScript中运行。为什么?我知道怎么&&
和 ||
工作,但列表?这个AS3具体吗?这是用其他语言吗?我是一个口着呼吸的PHP / AS2程序员。或者每个人都已经知道这一点,我是一个不能正确阅读文档的工具?
This runs in ActionScript 3 and JavaScript. Why? I know how &&
and ||
work, but a list? Is this AS3 specific? Is this in other languages? I'm a mouth breathing PHP/AS2 programmer. Or did everyone already know this and I'm a tool for not reading documentation properly?
AS3
if (true, true, true) {
trace("true?")
}
//result - "true?" traced
JavaScript
JavaScript
if (true, true, true) {
alert("true?");
}
//result - "true?" alert message popped up
if (false, false, false) {
alert("true?");
}
else {
alert("false");
}
//result - "false" alert message popped up
if(true, false, false) {
alert("true?");
}
else {
alert("false");
}
//result - "false" alert message popped up
推荐答案
我认为JavaScript有一个像C这样的逗号运算符,它接受多个参数并返回最后一个参数。它通常用于你想要初始化多个值的循环:
I presume JavaScript has a comma operator like C, which takes multiple arguments and returns the last one. It's typically used to for loops where you want to initialize more than one value:
for(i=0, j=0; j< 10; j++) {
...
}
这篇关于AS3 / JavaScript if语句逗号而不是& &安培;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!