gpt4 book ai didi

JavaScript 性能 : access time of properties - 'this' vs 'global object' vs 'variable'

转载 作者:行者123 更新时间:2023-11-29 21:21:57 26 4
gpt4 key购买 nike

var globalObject = { x: 0 }; // some global object with 'x' property

function Object()
{
this.x = 0;
}

Object.prototype.TestPerformance = function()
{
var xVar = 0;
}

从函数 TestPerformance 中,这些属性/变量的访问时间顺序是什么?

this.x 对比 globalObject.x 对比 xVar

最佳答案

将依赖于实现,如果不查看引擎源代码是不可知的。

但最好的近似值:

this.x 

O(1) 时间/复杂度

globalObject.x

O(1) 时间/复杂度

假设 LexicalEnvironments 在编译时被搜索。

var xVar

O(1) 时间/复杂度

关于JavaScript 性能 : access time of properties - 'this' vs 'global object' vs 'variable' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38334570/

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