javascript react-native 中 `this` 的上下文

context of `this` in javascript react-native

我在这里关注 react-navigation navigator tutorial 并且对使用 this.navigator = nav

设置 this.navigator 的方式感到困惑

完整代码如下:

import { NavigationActions } from 'react-navigation';

const AppNavigator = StackNavigator(SomeAppRouteConfigs);

class App extends React.Component {
  someEvent() {
    // call navigate for AppNavigator here:
    this.navigator && this.navigator.dispatch(
      NavigationActions.navigate({ routeName: someRouteName })
    );
  }
  render() {
    return (
      <AppNavigator ref={nav => { this.navigator = nav; }} />
    );
  }
}

根据我的理解(至少对于[=29=以外的编程语言],<AppNavigator ref={nav => { this.navigator = nav; }} />中的this应该是指AppNavigator,因此,代码如何在 someEvent 中似乎访问了由该代码设置的相同 this.navigator

任何线索将不胜感激。提前致谢!

An arrow function expression has a shorter syntax than a function expression and does not bind its own this

from MDN

因此 this 绑定到 App,这解释了行为。