哪个更快:document.location.pathname或myOwnObj.pathname
Which is faster: document.location.pathname or myOwnObj.pathname?
我正在努力优化我的JavaScript代码以提高速度。
我需要频繁访问document
对象的某些属性,如document.location.pathname
,甚至更糟的是,document.documentElement.innerText
。
哪个更快:
-
每次从
document
或访问这些属性 -
将它们存储为我自己对象的属性,以便我可以像
myObj.pathname
和myObj.innerText
一样访问它们?
测试它。
虽然浏览器之间存在一些差异,但缓存对象确实可以加快查找速度。
与访问对象属性两次而不是一次相比,"更快"。我真的很怀疑这是应用程序中的瓶颈。在任何情况下,在尝试优化像这样的小事之前,先对其进行概要分析。
相关文章:
- 正在使用$location.path(.)路由ng视图
- Reg-ex,用于解析window.location.pathname并返回个/s
- addClass('active') with window.location.pathname - u
- Javascript - 获取 location.pathname + location.search - 不占用所有部
- window.location.pathname Chrome vs Mozilla
- parent.window.location.pathname 返回未定义
- windows.location.pathname不起作用
- 使用history.pushState()时更新整个location.pathName
- 将location.pathname和location.search一起设置
- 如何“;转换“;window.location.pathname从对象到字符串
- 哪个更快:document.location.pathname或myOwnObj.pathname
- 在location.pathname前添加哈希值
- what return 'windows.location.pathname'?
- 如何使用位置.Href代替location.pathname
- 如何检查数组中的字符串是否在URL/window.location.pathname中
- 如何从window.location.pathname中删除尾部斜杠
- 如何防止window.location.pathname在URL中转义字符
- 如何从window.location.pathname获取文件名
- 相当于NodeJS中的window.location和window.pathname
- # for window.location.pathname