How are javascript properties added and searched on objects?

综合技术 2018-05-18 阅读原文

When adding properties to a JavaScript object are they added in an ordered way (alphabetical etc). And if so does that mean when you lookup a property on a JavaScript object that a quick algorithm is used like a binary tree search? I did a search for this and just found lots of explanations for prototype inheritance which I already understand I'm just interested in how a property is looked up within a single level of the prototype chain.

That entirely depends on the implementation. Google's V8 engine probably does it differently than Firefox's JagerMonkey. And they almost certainly does it different than IE6. Looking up a property in an object is just an interface (a fairly common Map interface as programmers would call it). The only thing Javascript guarantees you is the methods of the interface, no details about implementation, and that's a good thing. It could be a hash table (probably) or it could be a linked list (less likely, but possible) or it could even be a binary search tree.

The point is that we don't know how it's implemented, nor should we. And you should make no assumptions about the implementation. As is common with abstraction in programming, just assume it's magic. 🙂

Hello, buddy!

责编内容by:Hello, buddy!阅读原文】。感谢您的支持!

您可能感兴趣的

JavaScript代码重构 前言 最近,我一直在使用多个步骤(具有“上一步” 和“下一步”按钮)的HTML表单,其中表单的各个部分具有相同的“其他” 复选框。我使用“ onchange ”的JavaScript事件检查何时CheckBox被选中,然后显示“...
Omi === Preact + Scoped CSS + Store System + Nativ... English | 简体中文 Omi https://www.npmjs.com/package/omi Omi === Preact + Scoped CSS + Store System + Native Supp...
if else condition in smarty .tpl for nth-child lis... I'm working with Smarty. I want to add an if else condition in my .tpl file for nth-child li/div classes. ...
The Basics of Creating and Mapping a Common Resour... Our Customer Enablement Manager, Clayton Shaver, recently demoed a deep dive on creating common resources in our newly ...
Python爬虫基本原理 爬虫基本原理 1. 什么是爬虫 请求网站并 提取 数据的 自动化 程序。 2. 爬虫基本流程 发起请求 通过HTTP库向目标站点发起请求,即发送一个Request,请求可以包含额外的headers等信息,等待服...