Skip to content

Instantly share code, notes, and snippets.

@alexesca
Last active June 11, 2020 02:54
Show Gist options
  • Save alexesca/688e9e23a48437de19a74fbfcd10713d to your computer and use it in GitHub Desktop.
Save alexesca/688e9e23a48437de19a74fbfcd10713d to your computer and use it in GitHub Desktop.
/** Taken from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions*/
function Person() {
// The Person() constructor defines `this` as an instance of itself.
this.age = 0;
setInterval(function growUp() {
// In non-strict mode, the growUp() function defines `this`
// as the global object (because it's where growUp() is executed.),
// which is different from the `this`
// defined by the Person() constructor.
this.age++;
}, 1000);
}
var p = new Person();
console.log(p.age)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment