Skip to content

Instantly share code, notes, and snippets.

@cyrus-and
cyrus-and / this.js
Last active July 9, 2019 11:50
JavaScript `this` examples from http://stackoverflow.com/a/12371105/477168
// JavaScript `this` examples from http://stackoverflow.com/a/12371105/477168
// The value of this in a function is sometimes called the "context" in which
// the function runs. The most important thing to understand is that a function
// object does not have a fixed context -- the value of this changes depending
// on how the function is called.
// If the function is called as a "raw" function (e.g., just do someFunc()),
// this will be window (or undefined if the function runs in strict mode).