Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError: Unexpected reserved word #558

Closed
sonicoder86 opened this issue Jan 22, 2015 · 4 comments
Closed

SyntaxError: Unexpected reserved word #558

sonicoder86 opened this issue Jan 22, 2015 · 4 comments

Comments

@sonicoder86
Copy link

Yesterday installed the new iojs version with nvm install iojs-v1.0.3 then wrote my first class definition. But for my disappointment i got the following error when tried to run a simple file:

/home/blacksonic/workspace/es6/class.js:3
class View {
^^^^^
SyntaxError: Unexpected reserved word
    at exports.runInThisContext (vm.js:54:16)
    at Module._compile (module.js:429:25)
    at Object.Module._extensions..js (module.js:464:10)
    at Module.load (module.js:341:32)
    at Function.Module._load (module.js:296:12)
    at Function.Module.runMain (module.js:487:10)
    at startup (node.js:111:16)
    at node.js:809:3

The content of the file:

"use strict";

class View {
    constructor(model) {
        this.model = model;
    }

    render() {
        console.log(this.model);
    }
}

var myView = new View({table: true});
myView.render();

I ran it with:
node --harmony es6/class.js
also tried it with

What i checked:

node -v
v1.0.3
@Fishrock123
Copy link
Contributor

Currently Classes are behind the --es_staging flag and in strict mode only. https://iojs.org/es6.html

This is because the spec had to be reconsidered a bit and the implementation has to be slightly adjusted. Class support should land when we ship the stable version of v8 4.1. (still going to be a few weeks at least).

@chrisdickinson
Copy link
Contributor

ES6 class syntax isn't supported yet – it was pulled from v8 due to some retooling of the spec as I understand it. It should be in soon, though; and it's available behind the --harmony-classes flag.

@Fishrock123
Copy link
Contributor

Oh, looks like you tried to run it with --harmony. Sorry about that.

The --harmony flag no longer exists and has mostly been superseded by --es_staging.

@Fishrock123
Copy link
Contributor

e.g. iojs --es_staging --use-strict -e "class A { constructor() { console.log('cats') }}; new A()" prints cats.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants