Than let’s play some questions(that are in order of importance) to figure it out to where this is pointing to.

1 — Is the function called with new (new binding)? If so, this is the newly constructed object.

function foo(a) {

this.a = a;

} var bar = new foo( 2 );

console.log( bar.a ); // 2

2 — Is the function called with call or apply (explicit binding), even hidden inside a bind hard binding? If so, this is the explicitly specified object.

function foo(){

console.log(this.a);

}

var obj = {

a:2

};

foo.call(obj); //2

3 — Is the function called with a context (implicit binding), otherwise known as an owning or containing object? If so, this is that context object.

function foo(){

console.log(this.a)

}

var obj = {

a: 2,

foo: foo

};

obj.foo(); //2

4 — Otherwise, default the this (default binding). If in strict mode, //pick undefined, otherwise pick the global object.

function foo(){

console.log(this.a)

}

var a = 2;

foo(); //2

Determining the this binding for an executing function requires finding the direct call-site of that function. So, once again those are the rules in order of precedence:

Called with new? Use the newly constructed object. Called with call or apply (or bind)? Use the specified object. Called with a context object owning the call? Use that context object. Default: undefined in strict mode, global object otherwise.