You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Explanation of "Return Statement" #7 is misleading #92
(function () {
console.clear();
function getName1() {
console.log("getName1", this.name);
}
Object.prototype.getName2 = function () {
console.log("Object.prototype.getName2", this.name);
};
Object.prototype.getName3 = () => {
console.log(
"Object.prototype.getName3",
this.name,
"Why does this one not work?"
); //https://stackoverflow.com/a/31755263/470749 because "Arrow functions provide a lexical this. It uses the `this` that is available at the time the function is evaluated." See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions
};
Object.prototype.getName4 = () => {
console.log(
"Object.prototype.getName4",
Object.getPrototypeOf(this).name,
"This one does not make sense"
);
};
let personObj = {
name: "Tony",
print: getName1
};
personObj.print();
personObj.getName2();
personObj.getName3();
personObj.getName4();
})();
Activity