4.2 The this Keyword

The type of this in an expression depends on the location in which the reference takes place:

  • In a constructor, instance member function, instance member accessor, or instance member variable initializer, this is of the this-type (section 3.6.3) of the containing class.
  • In a static member function or static member accessor, the type of this is the constructor function type of the containing class.
  • In a function declaration or a function expression, this is of type Any.
  • In the global namespace, this is of type Any.

In all other contexts it is a compile-time error to reference this.

Note that an arrow function (section 4.11) has no this parameter but rather preserves the this of its enclosing context.