知识库首页 知识库-世界 js-cache-property-access.md

js cache property access

本地来源:Knowledge/World/项目/Practice/Claude-Skills/vercel-react-best-practices/rules/js-cache-property-access.md


title: Cache Property Access in Loops impact: LOW-MEDIUM impactDescription: reduces lookups tags: javascript, loops, optimization, caching


Cache Property Access in Loops

Cache object property lookups in hot paths.

Incorrect (3 lookups × N iterations):

for (let i = 0; i < arr.length; i++) {
  process(obj.config.settings.value)
}

Correct (1 lookup total):

const value = obj.config.settings.value
const len = arr.length
for (let i = 0; i < len; i++) {
  process(value)
}

本文档为站内渲染。原始文件本地路径:saas/source/knowledge-world/Knowledge-World-项目-Practice-Claude-Skills-vercel-react-best--7435d3.md(仅本地保留,不入库不部署)