Friday, 5 May 2017

ES6 Class property undefined

class Person{
constuctor(name){
    this.name = name;
}

speak(){
    alert('My name is ' + this.name);
}

}

var james = new Person('james');

james.speak();

I'm trying learn ES6 classes for some node stuff. Every example I find says this should work, but name is always undefined. I must be missing something really simple.

I have a fiddle here: https://jsfiddle.net/gxjhmgyu/



via user3806429

No comments:

Post a Comment