头图

The secret of JS prototype chain and Objective-C memory layout can not be said

fantasticbaby
中文
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

阅读 969

无线前端技术
关于无线前端开发的各种技术。包括多端融合能力、动态化、工程化、SDK 输出。iOS、Hybrid、H5、JS、Node...

杭州 - iOS- 家庭布偶猫,喜欢布偶可联系我

1k 声望
3.9k 粉丝
0 条评论

杭州 - iOS- 家庭布偶猫,喜欢布偶可联系我

1k 声望
3.9k 粉丝
文章目录
宣传栏