All Objects
Function Object
METHOD: Function::call
Function.
call
(thisArg[, arg1[, arg2[, ...]]])
The
call
method allows you to call a method from another object. This means you only need to write an object once and just apply it to any other objects that make use of it. The following example first creates an object called Car which has three properties. Then a second object is created called HireCar which (beside others) also has those same properties. So, instead of having to rewrite those properties, the HireCar object uses the
call
method to inherit them from the Car object. Note that that you can assign a different
this
object when calling an existing function.
Code:
function car(make, model, year)
{this.make = make, this.model = model, this.year = year}
function hireCar(carNo, make, model, year)
{this.carNo = carNo, car.call(this, make, model, year)}
NOTE
The
call
method is very similar to the
apply
method, but differs in that with
call
you cannot have the now deprecated
arguments
array as one of its parameters.
Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information