AS3 / JavaScript if语句逗号而不是& &安培; [英] AS3/JavaScript if statement commas instead of & &

查看:237
本文介绍了AS3 / JavaScript if语句逗号而不是& &安培;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这在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语句逗号而不是&amp; &安培;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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