gpt4 book ai didi

javascript - 为缩小与优化编写 JavaScript

转载 作者:搜寻专家 更新时间:2023-11-01 05:12:02 25 4
gpt4 key购买 nike

<分区>

通过优化,我的意思是例如决定使用基本的 for 循环还是使用 Array.prototype.forEach() 取决于哪个实现似乎更快浏览器等(在某些情况下,这可以扩展到微优化,they say can be dangerous。)

这是“为缩小而写”的含义示例:

if(foo === bar) {
return true;
} else {
return false;
}

// writing the following instead, which reduces size by a few bytes

return foo===bar; //will return true or false, depending on what the statement evaluates to

有些人可能会争辩说使用 if else 语句乍一看更易读,但我会说第二种编写方式可以更好地缩小。

就缩小而言,据我了解,这样做的主要目的是减少服务器响应时间。

为缩小和服务器响应时间而编写与可读性、为“优化”而编写之间的平衡是什么?

编辑
人们可能会将问题改写为为优化而编写与为使代码“缩小”而编写

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