在Javascript中将多个变量分配给相同的值 [英] assign multiple variables to the same value in Javascript

查看:145
本文介绍了在Javascript中将多个变量分配给相同的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JavaScript文件中初始化了全局范围内的几个变量:

I have initialized several variables in the global scope in a JavaScript file:

var moveUp, moveDown, moveLeft, moveRight;
var mouseDown, touchDown;

我需要将所有这些变量设置为false,这是我目前的代码:

I need to set all of these variables to false, this is the code I currently have:

moveUp    = false;
moveDown  = false;
moveLeft  = false;
moveRight = false
mouseDown = false;
touchDown = false;

有没有办法可以将所有这些变量设置为一行代码中的相同值,或者是我目前有最好的方法来执行此操作的代码

Is there any way that I can set all of these variables to the same value in one line of code, or is the code I currently have the best way to do this

推荐答案

没有什么可以阻止你做

moveUp = moveDown = moveLeft = moveRight = mouseDown = touchDown = false;

检查此示例

var a, b, c;
a = b = c = 10;
console.log(a + b + c)

这篇关于在Javascript中将多个变量分配给相同的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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