this Keyword

this Schlüsselwort/Variable

Spezielle Variable, die für jeden Execution Context (jede Funktion) erstellt wird. Nimmt den Wert des "Eigentümers" der Funktion an, in der das Schlüsselwort this verwendet wird (zeigt auf ihn).

this ist nicht statisch. Es hängt davon ab, wie die Funktion aufgerufen wird, und der Wert wird erst zugewiesen, wenn die Funktion tatsächlich aufgerufen wird.

Methodthis = <object that is calling the method>

const jonas = {
	name: 'Jonas',
	year: 1989,
	calcAge: function() {
		return 2037 - this.year
	}
};
;

Simple function callthis = undefined

Arrow functionsthis = <this of surrounding function (lexical this)>

Event Listenerthis = <DOM element that the hander is attached to>

Zuletzt aktualisiert