So I was reading the book Professional Javascript for Web developers and came across the following examples.
var object = {
name: "my Object",
getName: function() {
return this.name;
}
}
The author then shows the following results:
object.getName(); // "my Object"
(object.getName)(); // "my Object"
(object.getName = object.getName)() // "undefined"
I understand the first case but have the following questions for case 2 and case 3.
Case 2: What does putting a parentheses around object.getName do? So far I only know that you can put parentheses around anonymous function to call it immediately (Immediately-invoked function expression). But what if the function is not anonymous?
Case 3: Why is this
not maintained after the assignment?