// Rest properties
require("babel-core").transform("code", {
plugins: ["transform-object-rest-spread"]
});
let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };
console.log(x); // 1
console.log(y); // 2
console.log(z); // { a: 3, b: 4 }
// Spread properties
let n = { x, y, ...z };
console.log(n); // { x: 1, y: 2, a: 3, b: 4 }
Ich versuche das obige Beispiel von http://babeljs.io/docs/plugins/transform-object-rest-spread/ und es funktioniert nicht.Objekt Ausbreitung funktioniert nicht in Knoten 7.5
let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };
^^^
SyntaxError: Unexpected token ...
at Object.exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:543:28)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:418:7)
at startup (bootstrap_node.js:139:9)
at bootstrap_node.js:533:3
Wenn ich es mit babel-node
laufen dann funktioniert es gut. Irgendeine Idee warum?
Sie können Ihren Babel-Aufruf nicht in dieselbe Datei wie den Code mit den experimentellen Funktionen einfügen ?! Für babel-node steckst du das Plugin in die Konfigurationsdatei – Bergi
, also wie soll ich das strukturieren? wenn das mein index.js ist – cherhan
Sie sagen, dass es gut funktioniert, wenn es mit babel-node ausgeführt wird. Was ist dein Ziel? – Bergi