Section 24.84. Function.call( ): invoke a function as a method of an object


24.84. Function.call( ): invoke a function as a method of an object

ECMAScript v3

24.84.1. Synopsis

function.call(thisobj, args...)

24.84.1.1. Arguments

thisobj

The object on which function is to be invoked. In the body of the function, thisobj becomes the value of the this keyword. If this argument is null, the global object is used.


args...

Any number of arguments, which will be passed as arguments to function.

24.84.1.2. Returns

Whatever value is returned by the invocation of function.

24.84.1.3. Throws

TypeError

If this method is invoked on an object that is not a function.

24.84.2. Description

call( ) invokes the specified function as if it were a method of thisobj, passing it any arguments that follow thisobj in the argument list. The return value of call( ) is the value returned by the function invocation. Within the body of the function, the this keyword refers to the thisobj object, or to the global object if thisobj is null.

Use Function.apply( ) instead if you want to specify the arguments to pass to the function in an array.

24.84.3. Example

 // Call the default Object.toString( ) method on an object that // overrides it with its own version of the method. Note no arguments. Object.prototype.toString.call(o); 

24.84.4. See Also

 Function.apply( ) 




JavaScript. The Definitive Guide
JavaScript: The Definitive Guide
ISBN: 0596101996
EAN: 2147483647
Year: 2004
Pages: 767

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net