Function.call

Allows you to call (execute) a method of an object in the context of a different object (the calling object).

Method of Function

Syntax

call( thisArg[, arg1[, arg2[, ...]]] )

Parameters

Parameter Description
thisArg Parameter for the calling object
arg1, arg2, ... Arguments for the object

Description

You can assign a different this object when calling an existing function. this refers to the current object, the calling object.
With call, you can write a method once and then inherit it in another object, without having to rewrite the method for the new object.

Examples

You can use call to chain constructors for an object, similar to Java. In the following example, the constructor for the product object is defined with two parameters, name and value. Another object, prod_dept, initializes its unique variable (dept) and calls the constructor for product in its constructor to initialize the other variables.

See also

Function.apply

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.