当使用es6功能模式时,输出未定义

时间:2017-08-16 07:50:48

标签: javascript ecmascript-6 scoping

let data2 = {
    address: 'New Delhi ',
    pin: '201206',
    details: () => {
        return this.address + " " + this.pin
    }
}

这里,当我调用data2.details()时,输出是未定义的,但是当使用es5模式时,

let data2 = {
    address: 'New Delhi ',
    pin: '201206',
    details: function () {
        return this.address + " " + this.pin
    }
}

它运作正常吗?

0 个答案:

没有答案