English 中文(简体)
印章 目标成员出入
原标题:Javascripts Object member access

我很想知道目标成员进入时间。 更确切地说,在<代码>window的物体上,I m基准接入时间。 我认为,我可以自行解释大多数行为,但我觉得听取一些意见更好。

使用情况:不同财产的不同存取时间?

• 简单测量法,如:

var loop = 100000;

console.time( bench );
while(loop--){
   if(window.JSON)
      var foo = 0;
}
console.timeEnd( bench );

The first strange thing is, it makes a different which property I m looking up. For instance, window.JSON seems to be faster to access, than window.localStorage. There are other propertys/methods which can get accessed even faster.
Since there is no specification or defination within in the the ECMA-262 Language Specification, which order keys must have in an object, I guess each browser vendor implements it s own logic in which order keys are stored in memory.
Could this be an explanation for this behavior? Like, JSON is one of the very first keys and location is more at the end? (In my test environment at least)

<>->-

我注意到的另一件事是,电话if(JSON)略高于if(window.JSON)。 如果我们忘记,由于可能的参考错误,你总是应该做第二次呼吁,那么这些呼吁应当有同样的准入时间。 I mnow of ECMAscripts conduct on nested member lookups (A nested member will causes the Javascriptenergy to go through the Object member resolution, each time a dot isborn/strong>, so window.href 速度必须低于<代码> 所在地.href,但在这种情况下,/code>与window.JSON之间是否有差别?

为此,了解<代码>window的最快途径 物体拥有特定财产/方法即使用IN的操作者。 就上述例子而言,这大约是十倍。

最佳回答

您通知的第一件奇怪的事情是:hostbject由浏览器执行。

解决另一条已建构体的工艺,以及你将获得比<代码>JSON/code>的同样结果。

现在,<代码>JSON vs window.JSON上的区别:

window is only a property on the global Object that points to un, when You access the window ID the name resolution process take place to que it.

基本参考:

JSON;

只收集一个识别资料(在范围链中),并且:

window.JSON;

收集识别资料(window)和财产调查(window.JSON/code>)。

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.