Instead of looking at this example, let us know:
var Room = function() { this.doors = 1; };
Rather, like call
, apply
will execute this function, but let you specify what this
. In the above example, I specify this.doors = 1
, which makes doors
member when we create our instance of Room
.
Now if I do this:
var ComputerRoom = function() { Room.apply(this);
I really say that this
in the context of the Room
constructor is actually an instance of ComputerRoom
, so I pass it to the apply
: Room.apply(this)
command.
source share