An Arrow Function does not define local bindings for arguments, super, this, or new.target. Any reference to arguments, super, this, or new.target within an Arrow Function must resolve to a binding in a lexically enclosing environment. Typically this will be the Function Environment of an immediately enclosing function. Even though an Arrow Function may contain references to super, the function object created in step 4 is not made into a method by performing MakeMethod. An Arrow Function that references super is always contained within a non-ArrowFunctionand the necessary state to implement super is accessible via thescopethat is captured by the function object of the Arrow Function.
箭头函数不是没有
arguments
,而是没有自己的arguments
,自己的这个限定语很重要。如果有这样的代码:
你会在箭头函数里得到
args: [1, 2, 3, 4]
,它来自于其父作用域。并且连
this
、super
、new.target
都没有自己的,全都来自父作用域。那你要非刨根问底,为啥这四个都没有,这玩意儿连 ES6 规范原文里都没写原因,你咋知道 ECMA 那帮人讨论草案的时候咋想的。
ES6 规范原文有关箭头函数的部分在:http://www.ecma-international...
相关原文(大致就只说要来自父作用域,并没有解释为啥,浏览器你就照这个规范这么做就行了):
下面有个人贴的别人的答案,竟然说箭头函数是严格模式、严格模式下不允许使用
arguments
。前半句倒是对,后半句简直是胡说八道误人子弟,竟然还有 5 个赞。