docs: JS原型链与Objective-C内存布局不能说的秘密

This commit is contained in:
LiuBinPeng
2021-10-06 12:01:32 +08:00
parent cdd427824c
commit 97d89e215d
7 changed files with 25 additions and 2 deletions

View File

@@ -0,0 +1,21 @@
# JS原型链与Objective-C内存布局不能说的秘密
## 一、原型链与 Objective-C 的秘密
![JS 原型借鉴于 Self 语言](./../assets/2021-10-06-JSPrototype.jpg)
![JS 属性、方法在原型链的访问](./../assets/2021-10-06-JSFunctionCallInPrototype.jpg)
假期看了本关于 JS 的书。很多地方就是已知知识。但是看到2个地方感觉和现有知识体系有关联蛮有意思。拍照记录了下
Javascript 借鉴了 Self 语言中关于原型的继承可能会比较陌生什么是“Self”
看看 JS 的表现:假设从对象 O 中查询属性 X
1. 如果 O 没有 X 这个自有属性,则会从 O 的原型对象查询属性 X
2. 如果原型对象也没有叫做 X 的自有属性,但它有自己的原型,则继续查询这个原型的原型
3. 这个过程会不断继续,直至找到属性 X 或者查询到一个原型为 null 的对象
可见,对象通过其 prototype 属性创建了一个用于继承属性的链条或链表。
其实Self 语言由派生自 Smalltalk也就是 Objective-C 的借鉴语言。访问 JS 对象属性、方法(找不到则从原型链上不断回溯,直到找到或者找到元类对象 null这个特性和 OC 一模一样。
关于 Self 语言有2个中文 PDF可供翻阅。[SELF:简洁的威力](./selfpower-zh.pdf)、[克隆的反攻](./crpitv13noble-zh.pdf)

View File

@@ -43,3 +43,4 @@
* [39、前端模块化演进之路](https://github.com/FantasticLBP/knowledge-kit/blob/master/Chapter2%20-%20Web%20FrontEnd/2.39.md)
* [40、“Electron” 一个可圈可点的 PC 多端融合方案](https://github.com/FantasticLBP/knowledge-kit/blob/master/Chapter2%20-%20Web%20FrontEnd/2.40.md)
* [41、sourceMap 闪亮登场](https://github.com/FantasticLBP/knowledge-kit/blob/master/Chapter2%20-%20Web%20FrontEnd/2.41.md)
* [42、JS原型链与Objective-C内存布局不能说的秘密](https://github.com/FantasticLBP/knowledge-kit/blob/master/Chapter2%20-%20Web%20FrontEnd/2.43.md)

Binary file not shown.

Binary file not shown.

View File

@@ -142,6 +142,7 @@
* [39、前端模块化演进之路](https://github.com/FantasticLBP/knowledge-kit/blob/master/Chapter2%20-%20Web%20FrontEnd/2.39.md)
* [40、“Electron” 一个可圈可点的 PC 多端融合方案](https://github.com/FantasticLBP/knowledge-kit/blob/master/Chapter2%20-%20Web%20FrontEnd/2.40.md)
* [41、sourceMap 闪亮登场](https://github.com/FantasticLBP/knowledge-kit/blob/master/Chapter2%20-%20Web%20FrontEnd/2.41.md)
* [42、JS原型链与Objective-C内存布局不能说的秘密](https://github.com/FantasticLBP/knowledge-kit/blob/master/Chapter2%20-%20Web%20FrontEnd/2.43.md)
* [Chapter3 - Server](https://github.com/FantasticLBP/knowledge-kit/blob/master/Chapter3%20-%20Server/chapter3.md)
* [1、利用分页和模糊查询技术实现一个App接口](https://github.com/FantasticLBP/knowledge-kit/blob/master/Chapter3%20-%20Server/3.1.md)

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB