你不知道的JavaScript(上卷).pdf-Qui-Note

书籍信息

书名:你不知道的JavaScript(上卷).pdf
作者:Kyle Simpson
翻译:赵望野 && 梁杰
大小:16.3M
格式:PDF
版权:归原作者所有,仅供学习使用,请24小时内删除!

目录:

第一部分 作用域和闭包
序...............................................................................................................................................................2
第 1 章 作用域是什么...................................................................................................................... 4
1.1 编译原理.....................................................................................................................................4
1.2 理解作用域.................................................................................................................................6
1.2.1 演员表 ............................................................................................................................6
1.2.2 对话 ................................................................................................................................6
1.2.3 编译器有话说 ................................................................................................................7
1.2.4 引擎和作用域的对话 ....................................................................................................9
1.2.5 小测验 ..........................................................................................................................10
1.3 作用域嵌套...............................................................................................................................10
1.4 异常...........................................................................................................................................12
1.5 小结...........................................................................................................................................12
第 2 章 词法作用域 .........................................................................................................................14
2.1 词法阶段...................................................................................................................................14
2.2 欺骗词法...................................................................................................................................17
2.2.1 eval...............................................................................................................................17
2.2.2 with...............................................................................................................................18
2.2.3 性能 ..............................................................................................................................20
2.3 小结...........................................................................................................................................21
目录 | V
第 3 章 函数作用域和块作用域...................................................................................................22
3.1 函数中的作用域.......................................................................................................................22
3.2 隐藏内部实现...........................................................................................................................23
3.3 函数作用域...............................................................................................................................26
3.3.1 匿名和具名 ..................................................................................................................27
3.3.2 立即执行函数表达式 ..................................................................................................28
3.4 块作用域...................................................................................................................................30
3.4.1 with...............................................................................................................................31
3.4.2 try/catch .....................................................................................................................31
3.4.3 let.................................................................................................................................32
3.4.4 const.............................................................................................................................35
3.5 小结...........................................................................................................................................36
第 4 章 提升.......................................................................................................................................37
4.1 先有鸡还是先有蛋...................................................................................................................37
4.2 编译器再度来袭.......................................................................................................................38
4.3 函数优先...................................................................................................................................40
4.4 小结...........................................................................................................................................41
第 5 章 作用域闭包 .........................................................................................................................43
5.1 启示...........................................................................................................................................43
5.2 实质问题...................................................................................................................................44
5.3 现在我懂了...............................................................................................................................47
5.4 循环和闭包...............................................................................................................................48
5.5 模块...........................................................................................................................................51
5.5.1 现代的模块机制 ..........................................................................................................54
5.5.2 未来的模块机制 ..........................................................................................................56
5.6 小结...........................................................................................................................................57
附录 A 动态作用域..........................................................................................................................58
附录 B 块作用域的替代方案........................................................................................................60
附录 C this 词法.............................................................................................................................64
附录 D 致谢.......................................................................................................................................67
第二部分 this 和对象原型
序.............................................................................................................................................................72
第 1 章 关于 this.............................................................................................................................74
VI | 目录
1.1 为什么要用 this ......................................................................................................................74
1.2 误解...........................................................................................................................................76
1.2.1 指向自身 ......................................................................................................................76
1.2.2 它的作用域 ..................................................................................................................79
1.3 this 到底是什么......................................................................................................................80
1.4 小结...........................................................................................................................................80
第 2 章 this 全面解析....................................................................................................................82
2.1 调用位置...................................................................................................................................82
2.2 绑定规则...................................................................................................................................83
2.2.1 默认绑定 ......................................................................................................................83
2.2.2 隐式绑定 ......................................................................................................................85
2.2.3 显式绑定 ......................................................................................................................87
2.2.4 new 绑定........................................................................................................................90
2.3 优先级.......................................................................................................................................91
2.4 绑定例外...................................................................................................................................95
2.4.1 被忽略的 this..............................................................................................................96
2.4.2 间接引用 ......................................................................................................................97
2.4.3 软绑定 ..........................................................................................................................98
2.5 this 词法..................................................................................................................................99
2.6 小结.........................................................................................................................................101
第 3 章 对象.....................................................................................................................................102
3.1 语法.........................................................................................................................................102
3.2 类型.........................................................................................................................................103
3.3 内容.........................................................................................................................................105
3.3.1 可计算属性名 ............................................................................................................106
3.3.2 属性与方法 ................................................................................................................107
3.3.3 数组 ............................................................................................................................108
3.3.4 复制对象 ....................................................................................................................109
3.3.5 属性描述符 ................................................................................................................ 111
3.3.6 不变性 ........................................................................................................................114
3.3.7 [[Get]].......................................................................................................................115
3.3.8 [[Put]].......................................................................................................................116
3.3.9 Getter 和 Setter...........................................................................................................117
3.3.10 存在性 ......................................................................................................................119
3.4 遍历.........................................................................................................................................121
3.5 小结.........................................................................................................................................124
第 4 章 混合对象“类”.................................................................................................................126
4.1 类理论.....................................................................................................................................126
4.1.1 “类”设计模式 ..........................................................................................................127
目录 | VII
4.1.2 JavaScript 中的“类”.................................................................................................128
4.2 类的机制.................................................................................................................................128
4.2.1 建造 ............................................................................................................................128
4.2.2 构造函数 ....................................................................................................................130
4.3 类的继承.................................................................................................................................130
4.3.1 多态 ............................................................................................................................132
4.3.2 多重继承 ....................................................................................................................134
4.4 混入.........................................................................................................................................134
4.4.1 显式混入 ....................................................................................................................135
4.4.2 隐式混入 ....................................................................................................................139
4.5 小结.........................................................................................................................................140
第 5 章 原型.....................................................................................................................................142
5.1 [[Prototype]]........................................................................................................................142
5.1.1 Object.prototype......................................................................................................144
5.1.2 属性设置和屏蔽 ........................................................................................................144
5.2 “类”.........................................................................................................................................146
5.2.1 “类”函数 ..................................................................................................................146
5.2.2 “构造函数”................................................................................................................149
5.2.3 技术 ............................................................................................................................151
5.3 (原型)继承...........................................................................................................................153
5.4 对象关联.................................................................................................................................159
5.4.1 创建关联 ....................................................................................................................159
5.4.2 关联关系是备用 ........................................................................................................161
5.5 小结.........................................................................................................................................162
第 6 章 行为委托............................................................................................................................164
6.1 面向委托的设计.....................................................................................................................165
6.1.1 类理论 ........................................................................................................................165
6.1.2 委托理论 ....................................................................................................................166
6.1.3 比较思维模型 ............................................................................................................170
6.2 类与对象.................................................................................................................................173
6.2.1 控件“类”..................................................................................................................174
6.2.2 委托控件对象 ............................................................................................................176
6.3 更简洁的设计.........................................................................................................................178
6.4 更好的语法.............................................................................................................................182
6.5 内省.........................................................................................................................................185
6.6 小结.........................................................................................................................................187
附录 A ES6 中的 Class................................................................................................................189