JavaScript/多重赋值:修订间差异
来自康健生活
小 文字替换 -“{{leftrightflex|”替换为“{{Double-columns|” 标签:ReplaceText 移动版编辑 移动版网页编辑 |
|||
| 第2行: | 第2行: | ||
== 实现 == | == 实现 == | ||
=== 解构 === | === 解构 === | ||
{{ | {{Double-columns|<syntaxhighlight lang="javascript"> | ||
const [a, b, c] = [1, 2, 3]</syntaxhighlight>|{{consoleout|<pre> | const [a, b, c] = [1, 2, 3]</syntaxhighlight>|{{consoleout|<pre> | ||
</pre>}}}} | </pre>}}}} | ||
| 第10行: | 第10行: | ||
==== 常量 ==== | ==== 常量 ==== | ||
==== 引用 ==== | ==== 引用 ==== | ||
{{ | {{Double-columns|<syntaxhighlight lang="javascript"> | ||
var a = b = c = []; | var a = b = c = []; | ||
c.push(1); | c.push(1); | ||
| 第18行: | 第18行: | ||
全局污染 | 全局污染 | ||
{{ | {{Double-columns|<syntaxhighlight lang="javascript"> | ||
(function() { var a = b = c = 1 })(); | (function() { var a = b = c = 1 })(); | ||
console.log(window.c)</syntaxhighlight>|{{consoleout|<pre>1 | console.log(window.c)</syntaxhighlight>|{{consoleout|<pre>1 | ||
</pre>}}}} | </pre>}}}} | ||
2026年11月26日 (四) 07:14的最新版本
引言
实现
解构
const [a, b, c] = [1, 2, 3]
连等
var a = b = c;
常量
引用
var a = b = c = [];
c.push(1);
console.log(c)
[1]
缺陷
全局污染
(function() { var a = b = c = 1 })();
console.log(window.c)
1
No categories