gpt4 book ai didi

javascript - "use strict"仅在调试中?

转载 作者:数据小太阳 更新时间:2023-10-29 04:31:21 26 4
gpt4 key购买 nike

我想知道当我完成编程并向任何人发布我的 JavaScript 文档时是否真的有必要包含 "use strict"。我喜欢使用它,因为它可以检查我的编码是否正确。

那么,当我向公众发布我的 JavaScript 文件时,我应该包含还是删除 use "use strict"

我问的原因是为了节省我的 JavaScript 文件的空间。

最佳答案

我发现了两种关于在生产中使用严格模式的观点:

There is no reason to ship “use strict” in your production code. There is no performance gain (verified with V8 team and Brendan a while ago) and I don’t need my users’ VMs doing the extra checks as well. Keep it development only, strip it out during build. This way you also avoid the concatenation issue you reference.

和:

There may not be a performance gain, but there’s also not a performance loss. In production, even more than in development, is where you want to be sure you’re noticing errors. Minimizing the changes between the development and production versions of the code is key to being able to debug issues quickly and efficiently. Yes it helps during development, but there’s no reason to pull it out of production code.

The source is in the comments at the bottom

当然,“use strict” 的那些 12b 权重不会改变任何事情。

关于javascript - "use strict"仅在调试中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10986675/

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