Je suis expérimenter avec l' await
mot-clé dans Node.js. J'ai ce script de test:
"use strict";
function x() {
return new Promise(function(resolve, reject) {
setTimeout(function() {
resolve({a:42});
},100);
});
}
await x();
Mais quand je le lance il en nœud-je obtenir
await x();
^
SyntaxError: Unexpected identifier
si je le lance avec node
ou node --harmony-async-await
ou, dans le Node.js la "repl" sur mon Mac avec Node.js 7.5 ou Node.js 8 (nightly build).
Curieusement, le même code fonctionne dans le Runkit JavaScript cahier de l'environnement: https://runkit.com/glynnbird/58a2eb23aad2bb0014ea614b
Ce que je fais mal?