爲什麼此代碼不起作用?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}`);
當我嘗試用
node app.ts
運行它,我有下:
[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
但我相信:
Before a = 1, b = 2
After a = 2, b = 1
TypeScript版本1.8.10
「打字稿版本1.8.10」 - 你跟節點運行它。你直接用節點運行它。你沒有把它轉換成JavaScript。它被視爲JavaScript。 – Quentin