I've been reading a little bit into execution contexts and lexical scoping. From my understanding, if a function is declared, it will have a reference to the lexical environment (LE) that defined that function. for example,
var x = 20;
function foo() {
console.log(x);
}
So the reason why foo has access to variable x is because foo's LE has a reference to the LE which created foo which is the global LE so it can search through the scope chain until it finds x.
however for the following snippet:
var stacy = {
name: 'stacy',
age: 33,
sayName: function() {
console.log(this.name);
}
}
What is the LE of the object stacy? (I believe it would be the global LE)
What is the LE of the sayName()? (if I omit the "this" keyword, why couldn't it find the variable "name" when the function couldn't find "name" in its own LE)?