Assignment Operators in One Statement

I'm wondering if JavaScript allows multiple addition-assignment operators in one statement. I know about multiple variable assignment, discussed here.

My current way of coding looks somewhat like this:

var x = someComplicatedFunction();
foo += x;
bar += x;

Is there a way to do something like this?

foo, bar += someComplicatedFunction();

You can put as many statements as you want in one line :

var x = someComplicatedFunction(); foo += x; bar += x;

If you want to do everything in one statement, it's more messy but it's doable :

bar -= foo - (foo += someComplicatedFunction());

But there's nothing magical letting you do everything in one statement without assignation and being readable.

链接地址: http://www.djcxy.com/p/69992.html

上一篇: 什么需要('jquery')返回以及为什么需要多个分配

下一篇: 赋值运算符在一个语句中