JavaScript scope, clouser and reference [duplicate]


function foo() {
    var a = 'foo a';

    return {
        a: function() {
          return this.a;
        },
        b: function() {
          return a;
        }
    }
}

var a = 'global a';

foo().a() // still return reference to the function same as foo().a
foo().a()();
foo().b();

Hello anybody.

Could you tell me why for.a() doesn’t return value, instead the foo.a()() does?!
I don’t get it. Thanks!

I tested on Chrome browser