This article is not an exploration of new knowledge. The article has no content. It is to see that the knowledge of two different fields is connected together, or the design ideas of the language are confirmed and I am happy and record it.
I read a book about JS during the holidays. Many places are known knowledge. But seeing two places feels related to the existing knowledge system, which is quite interesting. Took a photo and recorded it
Take a look at the performance of JS: suppose to query property X from object O
- If O does not have its own attribute of X, then the attribute X will be queried from O’s prototype object
- If the prototype object does not have its own property called X, but it has its own prototype, continue to query the prototype of this prototype
- This process will continue until the property X is found or an object whose prototype is null is found
It can be seen that the object creates a chain or linked list for inheriting properties through its prototype property.
Comparing the memory layout of OC objects, the access routines of attributes or methods are consistent.
In fact, the Self language is derived from Smalltalk, which is a reference language for Objective-C. Access to JS object properties and methods (if not found, it will continue to trace back from the prototype chain until the metaclass object null is found or found). This feature is exactly the same as OC.