Skip to content

Commit 5830d47

Browse files
committed
feat[ptr]: V8 源码分析 变量提升
"变量提升"在 V8 里根本没有一个叫 Hoist 的运行时操作——它是编译期 DeclareVariable 时选择作用域的静态决策,配合 InitializationFlag 控制运行时是否允许访问
1 parent 574b1cc commit 5830d47

4 files changed

Lines changed: 13 additions & 1 deletion

File tree

JS/preJS/1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit f986c4c4f74b49bdcb4437b869e3c0e50ba1b735

JS/test/变量提升.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
console.log(typeof (x)); // ✓ undefined(var 提升 + 初始化)
2+
var x = 1;
3+
4+
// ====
5+
6+
let y = 'outer';
7+
{
8+
console.log(y); // ReferenceError,而不是 'outer'
9+
let y = 'inner'; // 块内的 y 已经提升占住了这个名字,外层 y 被屏蔽
10+
}

React/sandboxs/React/source

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 8d7fd30807ec8f674cc1725a94194a8bbdbc0c63

0 commit comments

Comments
 (0)