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!阅读原文】。感谢您的支持!

您可能感兴趣的

Array deletes in JavaScript Array deletion is an often misunderstood concept in JavaScript, partly because t...
Where can I learn Web programming from the beginni... I tried doing tutorials but it is unorganized and unstructured, where can I lea...
Understand Async Iterators Without Really Trying Nobody likes a callback. It’s like a modern day equivalent of a GOTO stateme...
Simple JavaScript connection, redirects ... my school is doing a 5 day html challenge next week and i'm practicing my idea, ...
前端 2017: 举要删芜 2017 年发生了很多事,想起来,嗯,确实有点多。我们都喜欢拿前端开发领域的变化之快开玩笑,而在过去几年中事实也确实如此。 尽管听起来可...