13.4 词法范围的变量

13.4.1 变量值的来源:静态的和动态的

下面是一个变量能够接收到值的两种方式。

第一种,静态地(词法地):变量的值由程序的书写解构决定,从父作用域中获取值。例如:

let x = 123;

function foo(y) {
    return x; // value received statically
}

第二种,动态地:通过函数调用获得值。例如:

function bar(arg) {
    return arg; // value received dynamically
}

13.4.2 箭头函数中的词法变量

this 的来源是一个区分箭头函数的重要方面:

  • 传统函数有一个动态的 this ,它的值取决于函数如何调用。
  • 箭头函数有一个词法的 this ,它的值取决于父作用域。

完整的从词法范围获取值的一组变量是:

  • arguments
  • super
  • this
  • new.target

results matching ""

    No results matching ""