이 코드가 작동하지 않는 이유는 무엇입니까?TypeScript : SyntaxError : 콘솔에서 "예기치 않은 토큰"메시지가 나타납니다.
[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
하지만 기대 :
나는 다음과 같은 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
그것을 실행하려고 나는 다음을 가지고있다
Before a = 1, b = 2
After a = 2, b = 1
TypeScript 버전 1.8.10
"타이프 라이터 버전 1.8.10"로 ES5합니다 - 당신은 노드를 실행 중입니다. 노드로 직접 실행하고 있습니다. 자바 스크립트로 변환하지 않습니다. 그것은 JavaScript로 취급되고 있습니다. – Quentin