I'm learning about "this" in JS and I have the following code:
var person1 = {
firstName: "John",
lastName: "Snow",
printName: function(){
console.log(this);
}
}
var person2 = {
firstName: "Aria",
lastName: "Stark",
printName: function(callbackFunction){
console.log(this);
callbackFunction();
}
}
person1.printName();
person2.printName(person1.printName);
The output of this code is:
person1
person2
window
I understand why to context is person1 and person2 accordingly but why when I call the callback the context is window and not person2?