小编ven*_*ber的帖子

TypeScript:SyntaxError:控制台中的“意外令牌”消息

为什么此代码不起作用?

我有以下app.ts

var a = 1;
var b = 3;
console.log(`Before a = ${a}, b = ${b}`);

[a, b] = [b, a];
console.log(`After a = ${a}, b = ${b}`);
Run Code Online (Sandbox Code Playgroud)

当我尝试使用

节点应用

我有下一个:

[a, b] = [b, a];
^

ReferenceError: Invalid left-hand side in assignment
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:139:18)
    at node.js:974:3
Run Code Online (Sandbox Code Playgroud)

但我期望:

Before a = 1, b = 2
After a = 2, b …
Run Code Online (Sandbox Code Playgroud)

javascript destructuring typescript

3
推荐指数
1
解决办法
8988
查看次数

标签 统计

destructuring ×1

javascript ×1

typescript ×1