简体   繁体   English

hasOwnProperty和对象的属性访问

[英]hasOwnProperty and object's properties access

I have very simple question.Is there any performance relation about accessing object's properties like object[property] and the number of properties ?? 我有一个非常简单的问题。关于访问对象的属性(例如object[property]object[property]的数量)是否存在性能关系? Is there some internal loop or something , same question about hasOwnProperty - any loops or just direct access like array[index] ?? 是否有一些内部循环或某些东西,关于hasOwnProperty相同问题-任何循环或只是直接访问,例如array[index]

JavaScript is a dynamic programming language: properties can be added to, and deleted from, objects on the fly. JavaScript是一种动态编程语言:可以动态地向对象添加属性或从对象中删除属性。 This means an object's properties are likely to change. 这意味着对象的属性可能会更改。 Most JavaScript engines use a dictionary-like data structure as storage for object properties - each property access requires a dynamic lookup to resolve the property's location in memory. 大多数JavaScript引擎使用类似字典的数据结构作为对象属性的存储-每个属性访问都需要动态查找以解析属性在内存中的位置。 This approach makes accessing properties in JavaScript typically much slower than accessing instance variables in programming languages like Java and Smalltalk. 这种方法通常使访问JavaScript中的属性比访问诸如Java和Smalltalk这样的编程语言中的实例变量慢得多。 In these languages, instance variables are located at fixed offsets determined by the compiler due to the fixed object layout defined by the object's class. 在这些语言中,由于对象类定义的固定对象布局,实例变量位于由编译器确定的固定偏移处。 Access is simply a matter of a memory load or store, often requiring only a single instruction. 访问仅是存储器加载或存储的问题,通常仅需要一条指令。

use V8 (JavaScript engine) for better performance. 使用V8(JavaScript引擎)以获得更好的性能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM