reactjs / reactjs/react.dev

Change Missing From Changelog: forEach() Loop's `Return` returns to forEach()'s invocation point, not to the calling function.

未关闭
#2,732 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
JavaScript
星标
11.8k
派生
7.9k
平均合并
1 天 11 小时
30 天内合并 PR
11

描述

Hey all,

I'm noticing that in upgrading to ReactJS Version 16.12.0 from 16.7.0, the behavior of foreach was changed, so that return returns to where foreach is called, and not the function calling the function containing the foreach. But I don't see this change here:

https://github.com/facebook/react/blob/master/CHANGELOG.md

Basically,

function1() {
	function2();
	console.log("function 1");
}

function2() {
	const arr = ['cool'];
	arr.forEach((var) => {
		return var;
	});
	console.log("function 2");
}

Before 16.12.0, console output was: "function 1", but now it is "function 2; function 1." This change appears to be against MDN documentation and internet consensus: https://stackoverflow.com/questions/34653612/what-does-return-keyword-mean-inside-foreach-function

But it should have been included in the changelog, though I am not seeing it. Let me know if I'm misunderstanding.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 CHANGELOG.md 以及 issue 中引用的 React 16.12.0 changelog 条目开始。根据链接的 MDN 和 Stack Overflow 参考资料验证报告的 forEach() 行为,然后确定 changelog 是否缺少条目;当报告得到验证且 changelog 在适用的情况下准确反映该版本发布时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, react
领域
documentation
Issue 类型
文档
难度
2/5
预计耗时
1-3 小时
活跃度
停滞
描述清晰度
基本清楚
新手友好度
30/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。