If you call a method:
a.b.c.d();
then this
is a.b.c
inside of the method (everything except the final function name).
If you call a constructor:
var x = new Something();
then this
is a new fresh object inside of Something().
Everywhere else this
is the global object (which is the same as window
in the browser).
this
is never a prototype. This can have a prototype.
In your example:
A.B = function() {
this.x(5);
}
this
is A
(which doesn't have to be a prototype of A.B
) if that method is called as A.B()
- and is a new object if that method is called as new A.B()
.