3 ms·
The way I remember it: this is whatever is before the dot when you call the function. E.g. for car.drive(); in the drive function, any reference to 'this' will
by mhansen 17y ago
The way I remember it: this is whatever is before the dot when you call the function.
E.g. for car.drive(); in the drive function, any reference to 'this' will get 'car'. If the function is called on it's own, as in 'drive()', 'this' will refer to the Global object (bad)
It's also possible to change 'this' by using the Function.prototype.apply() method, which allows you to pass a 'context' parameter that will become 'this'.