The arrow function preserves the lexical area in which it was defined. Thus, this in your hello function is the same as this when the function was defined, and not the object on which this property is. This is essentially a shorthand for ES5
function() { return 'hello, ' + this.username; }.bind(this);
What you want is something like
let obj = { username: 'Hans Gruber', hello() {return `hello, ${this.username}`;} };
Igor Dubinskiy
source share