I'm using angular 8 and here's my code.
export class AppComponent {
  public auth2: gapi.auth2.GoogleAuth = null;
  public signInStatus: string = "Unknown";
  constructor(private zone: NgZone, private httpClient: HttpClient) {}
  public ngAfterViewInit() {
    this.googleInit();
  }
  public googleInit() {
    // gapi javascript library is loaded in index.html file using
    // <script src="https://apis.google.com/js/client:platform.js"></script>
    // here I just use it
    gapi.load('auth2', () => {
      this.auth2 = gapi.auth2.init({
        client_id: '2xxxxxp.apps.googleusercontent.com',
        cookiepolicy: 'single_host_origin',
        scope: 'profile'
      });
      this.auth2.then( (googleAuth: gapi.auth2.GoogleAuth) => {
        let isSignedIn: boolean = googleAuth.isSignedIn.get();
        // if I use here debugger; then this referes to AppComponent
        // I come from javascript world, where 'this' refers to current scope
        // why does 'this' refere to AppComponent here?
        this.updateSignInStatus(isSignedIn);
      }, onFailure => {
          console.log("Initialization failed");
      });
    });
  }
  public updateSignInStatus(signedIn: boolean) {
    this.zone.run(() => {
      debugger;
      // I though that 'this' here referes to current scope which
      // is anonymous function. The same question as below
      this.signInStatus = signedIn ? "Yes" : "No";
    });
  } 
I want to understand why 'this' in anonymous functions refers to AppComponent. What have I missed. Perhaps some links to documentation.

