Function.call() (Method)

Uses a function object as if it belonged to another target object.

Availability:

ECMAScript edition - 3
JavaScript - 1.3
JScript - 5.5
Internet Explorer - 5.5
Netscape - 4.06
Property/method value type:Function result
JavaScript syntax:-myFunction.call(anObject, anArgumentList)
Argument list:anArgumentListA list of arguments
anObjectAn object to apply the function to

If you want to force a particular function implementation to be used on an object, you can locate the one you want and pass it an object on which to operate. The function then executes as if it were a property of the passed object instead of the receiving object.

This can be useful to restore some functionality that may have been overridden or to share a function definition between several objects.

This is effectively like adding the function as a property to the target object, executing it, passing the arguments to it and then deleting the function property afterwards. Applying a function is a lot easier.

This is similar to the apply() method which passed the arguments as an array. This passes them as a comma separated list.

Example code:

   // Call this function against another object
   myFunctionObject.call(myTargetObject, 100, "aaa");

See also:Event handler scope

Cross-references:

ECMA 262 edition 3 - section - 15.3.4.4