头图
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.

JS 原型借鉴于 Self 语言
JS 属性、方法在原型链的访问
OC对象内存布局

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

Javascript borrows the inheritance of prototypes in the Self language. It may be unfamiliar. What is "Self"?
Take a look at the performance of JS: suppose to query property X from object O

  1. If O does not have its own attribute of X, then the attribute X will be queried from O’s prototype object
  2. 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
  3. 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.

There are 2 Chinese PDFs for reading about the Self language. SELF: the power of , clone counterattack


杭城小刘
1.1k 声望5.1k 粉丝

95 - iOS - 养了4只布偶猫