Easy question no doubt, but I'm confused why variable 'a' is undefined when called from bar(). I would expect it to be 'global a' as bar is called from the global context
var a = 'global a'
function foo1() {
console.log(this.a);
}
var obj1 = {
a: 3,
foo1: foo1
}
var bar = obj1.foo1;
bar(); // why does this result in 'undefined rather than 'global a'?
Can anyone point out what I'm missing please?