Could someone provide an explanation of the scope binding in this code snippet?
window.name = "window";
object = {
name: "object",
method: function() {
nestedMethod: function() {
console.log(this.name);
}
nestedMethod();
}
}
object.method(); // prints 'window'
I am curious about the behavior of this
. Why does it lose its scope and default to the global scope? Do all anonymous functions we create end up in the global scope?