ES6箭头功能词典在V8中 [英] ES6 arrow function lexical this in V8

查看:148
本文介绍了ES6箭头功能词典在V8中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用胖箭头函数使用以下ES6代码:

I have the following ES6 code using a fat arrow function:

var test = {
  firstname: 'David',
  fn: function() {
    return ['one', 'two', 'tree'].map(() => this.firstname)
  }
}
console.log(test.fn())

根据箭头函数应该工作,我希望这个成为测试对象。 ES6Fiddle ,Traceur和Firefox产生的预期输出是 [David,David,David ]

According to how arrow functions are supposed to work I'd expect this to be the test object. ES6Fiddle, Traceur and Firefox produce the expected output which is ["David", "David", "David"].

在Chrome中使用 chrome启用这些功能chrome:// flags /#enable-javascript-harmony ,但是,我得到 [undefined,undefined,undefined] 。如果您 console.log(this),则表明它是窗口对象,并在严格模式下收到错误。

When enabling those features in Chrome using chrome://flags/#enable-javascript-harmony, however, I get [undefined, undefined, undefined]. If you console.log(this) it shows that it is the window object and you get an error in strict mode. Is the lexical this for ES6 arrow functions not implemented in V8 yet?

推荐答案

c / p>词汇这个是ES8的功能的最后一部分,在v8中登陆,这就是为什么它仍然在一个标志之后,还没有准备好发货的原因。 Igalia的Adrian Perez正在执行箭头功能,最终补丁几乎可以在几个TurboFan问题解决之后立即着陆: https:/ /codereview.chromium.org/883823002/

Lexical this is the last part of ES6 arrow functions to land in v8 and it is the reason why it is still behind a flag and not ready to ship yet. Adrian Perez at Igalia is implementing arrow functions and the final patch is almost ready to land as soon as a few TurboFan issues are worked out: https://codereview.chromium.org/883823002/

这篇关于ES6箭头功能词典在V8中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆