gpt4 book ai didi

javascript - 将 thisArg 传递给映射函数

转载 作者:行者123 更新时间:2023-11-29 18:58:35 25 4
gpt4 key购买 nike

<分区>

这个问题可能已经有人问过了。来自documentation ,我们可以将 thisVariable 传递给 map 函数。

var foo=[1,2].map(function(){return this.length},[2,4]); // [2,2]

但是,ES6 中的这种语法会返回其他内容

var foo=[1,2].map(_ => this.length ,[2,4]); // [0,0]

返回的[0,0]是什么?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com