codecombat / esper.js

A javascript self-interpreter with a focus on sandboxed execution and runtime introspection.
MIT License
98 stars 19 forks source link

Update README to clarify what versions of JavaScript are supported #13

Open ngocdaothanh opened 6 years ago

ngocdaothanh commented 6 years ago

Please update README to clarify what versions of JavaScript are supported.

basicer commented 6 years ago

It's ES5 strict mode with some parts of ES6 implemented, and some parts of non-strict mode implemented. (And possibly some parts of ES5 missing).

Any thoughts on the best way to explain this?

ngocdaothanh commented 6 years ago

It seems that class inheritance in ES6 is not supported.

basicer commented 6 years ago

It should be, atleast to some degree.

See https://github.com/codecombat/esper.js/blob/master/contrib/test-suites/js-corpus/classes.js

What's not working for you?

ngocdaothanh commented 6 years ago

What's not working for you?

class Animal {
    constructor(name) {
        this.name = name
    }
}

class Cat extends Animal {
    talk() {
        console.log(`Meow, my name is ${this.name}`)
    }
}

const kitty = new Cat('Kitty')
kitty.talk()
ngocdaothanh commented 6 years ago

Is it easy to improve esper.js to support the example above?

basicer commented 6 years ago

Should be easy enough.

The bug here is that the Cat class doesn't inherit the constructor from Animal. For example the below works.

class Animal {
    constructor(name) {
        this.name = name
    }
}

class Cat extends Animal {
    constructor(name) { super(name); }
    talk() {
        console.log(`Meow, my name is ${this.name}`)
    }
}

const kitty = new Cat('Kitty')
kitty.talk()
basicer commented 6 years ago

@ngocdaothanh Fixed in 6a2797b9dd6ea40f132930113d5927e07e1dd5b0