2016-11-21 3 views
-2

Ich bin sehr neu in ES6, und habe einen Beispiel-Klassencode in node.js mit Webstorm IDE geschrieben.SyntaxError: Block-Bereich Deklarationen in node.js webstorm

'user strict'; 

class PersonClass { 
    constructor(name) { 
     this.name = name; 
    } 

    sayName() { 
     console.log(this.name); 
    } 
} 

let person = new PersonClass('My Name'); 
person.sayName(); 

Wenn ich den Code ausführen wird einen Fehler

class PersonClass { 
^^^^^ 

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode 
    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 

Auch wenn ich babel-cli installiert habe, babel-Voreinstellungen-es2015. Wie kann ich es reparieren.

+1

"user streng" zu schreiben? Dieser Benutzer hier anscheinend nicht so streng mit der Rechtschreibung ... ;-P – deceze

+0

@deceze mein Schlechter habe das nicht bemerkt. Danke :) –

+0

Auch auf Knoten 6 aktualisieren und das wird kein Problem sein. – loganfsmyth

Antwort

0

Sie einen Tippfehler haben, versuchen use strict statt user strict

+0

oops mein Schlechter, Danke @Juan –

Verwandte Themen