Let's see examples:
first:
var user = {
firstName: "John",
sayHi: function() {
alert( this.firstName );
}
};
setTimeout(function() {
user.sayHi(); // John
}, 1000);
second:
var user = {
firstName: "John",
sayHi: function() {
alert( this.firstName );
}
};
setTimeout(user.sayHi, 1000);// undefined
Why in the second example undefined? And how does that work?