It will not inherit the properties of Box
that way. That is because you are calling the Box
function on the global context and the value of this
will point to the global object window
. To change the value of the this
inside the function, use call()
or apply()
or even bind()
.
When you change the value of this
this way inside the Player
function, the initialisation code inside Box
will be run with the instance of Player
as its context.
function Player(Size,Position)
{
Box.call(this,Size,Position); //the this value will point to instance of Player
}