Last active
June 11, 2020 02:54
-
-
Save alexesca/688e9e23a48437de19a74fbfcd10713d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 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