ES6 箭头函数中关于`arguments` 的官方信息? [英] Official information on `arguments` in ES6 Arrow functions?

查看:24
本文介绍了ES6 箭头函数中关于`arguments` 的官方信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(() => console.log(arguments))(1,2,3);

// Chrome, FF, Node give "1,2,3"
// Babel gives "arguments is not defined" from parent scope

根据 Babel(以及我可以告诉最初的 TC39 建议),这是无效的",因为箭头函数应该使用它们的父作用域作为参数.我能找到的唯一与此相矛盾的信息是一条评论说这被 TC39 拒绝了,但我找不到任何支持这一点的信息.

According to Babel (and from what I can tell initial TC39 recommendations), that is "invalid" as arrow functions should be using their parent scope for arguments. The only info I've been able to find that contradicts this is a single comment saying this was rejected by TC39, but I can't find anything to back this up.

只是在这里寻找官方文档.

Just looking for official docs here.

推荐答案

Chrome、FF、node这里好像有问题,babel是对的:

Chrome, FF, and node seem to be wrong here, Babel is correct:

箭头函数在其作用域内没有自己的arguments 绑定;调用它们时不会创建参数对象.

Arrow functions do not have an own arguments binding in their scope; no arguments object is created when calling them.

在这里寻找官方文档

箭头函数表达式求值为 具有 [[ThisMode]] 设置lexical,当这样被称为声明实例化 不会创建参数 对象.甚至有一个特定的注释 (18 a) 指出箭头函数从来没有参数对象.".

Arrow function expressions evaluate to functions that have their [[ThisMode]] set to lexical, and when such are called the declaration instantiation does not create an arguments object. There is even a specifc note (18 a) stating that "Arrow functions never have an arguments objects.".

这篇关于ES6 箭头函数中关于`arguments` 的官方信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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