我正在尝试优化我的 JavaScript 代码以提高速度。
document
我有需要经常访问的对象的某些属性,例如document.location.pathname
,甚至更糟的是document.documentElement.innerText
.
哪个会更快:
从
document
每次访问这些属性,或将它们存储为我自己的对象之一的属性,以便我可以像
myObj.pathname
和myObj.innerText
?
我正在尝试优化我的 JavaScript 代码以提高速度。
document
我有需要经常访问的对象的某些属性,例如document.location.pathname
,甚至更糟的是document.documentElement.innerText
.
哪个会更快:
从document
每次访问这些属性,或
将它们存储为我自己的对象之一的属性,以便我可以像myObj.pathname
和myObj.innerText
?