0

I can't access my object property with this ES6 expression :

const obj =
{
    name: 'john',
    test: () => console.log('hello'+this.name)
} 
obj.test()

I only get "hello", and with this expression it works :

const obj =
    {
        name: 'john',
        test: function() {
            console.log('hello'+this.name)
        }
}

What's happening here ?

naspy971
  • 1,137
  • 2
  • 13
  • 31
  • 1
    http://exploringjs.com/es6/ch_arrow-functions.html#sec_traditional-functions-bad-non-methods – zerkms Jun 11 '17 at 23:15
  • 1
    Lots of duplicates: [`[ecmascript-6] arrow function object literal`](https://stackoverflow.com/search?q=%5Becmascript-6%5D+arrow+function+object+literal) – Felix Kling Jun 11 '17 at 23:23

0 Answers0