Mon, 23 Jan 2017 04:12:58 +0000

Temporal Dead Zone, TDZ

介绍一个样例

var x = 1;
function foo(x = x) {
	console.log(x);
}
foo();
// Uncaught ReferenceError: x is not defined

以上可以转成为如下代码,便于理解:

var x = 1;
function foo() {
	let x = x;
	console.log(x);
}
foo();

我个人理解为,let 变量没有前置,导致执行到某一行,该行没有定义。

References

https://github.com/Asurvovor/translation/issues/1



blog comments powered by Disqus