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

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

问题描述

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

  

// Chrome,FF,Node给出1,2,3
// Babel给出了父参数中的参数未定义

根据Babel(从我可以告诉初始的TC39建议),这是无效的,因为箭头函数应该使用他们的父范围的参数。唯一的信息,我能够发现与此矛盾的是一个单一的评论,这被TC39拒绝,但我找不到任何东西来支持。



解决方案

Chrome,FF和节点似乎在这里错了,Babel是正确的: / p>

箭头函数在其范围内没有自己的参数绑定;调用它们时不会创建参数对象。


在这里寻找官方文档


箭头函数表达式计算函数将他们的[[ThisMode]]集设置为 lexical ,当这样被称为声明实例化不会创建一个 参数对象。甚至有一个特殊说明(18 a),指出箭头函数从来没有参数对象。


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

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

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, and node seem to be wrong here, Babel is correct:

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

looking for official docs here

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 Arrow函数中的“参数”的官方信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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