contents   index   previous   next



Function call()

syntax:

function.call([thisObj[, arguments[, ...]]])

where:

thisObj - An object that will be used as the "this" variable while calling this function. If this is not supplied, then the global object is used instead.

 

arguments - list of arguments to pass to the function. Note that the similar method Function apply() can receive the same arguments as an array. Compare the following ways of passing arguments:

 

   // Uses an Array object

function.apply(this, argArray)

   // Uses brackets

function.apply(this,[arg1,arg2])

   // Uses argument list

function.call(this,arg1,arg2)

return:

variable - the result of calling the function object with the specified "this" variable and arguments.

 

description:

This method is almost identical to calling the function directly, only the user is able to supply the "this" variable that the function will use. Otherwise, it is the same.

 

see:

Function(), Function.apply()

 

example:

// The following code:

 

var myFunction = new Function("arg", 

                     "return this.a + arg");

var obj = { a:4 };

myFunction.call( obj, 5 );

 

// This code fragment returns the value 9,

// which is the result of fetching this.a

// from the current object (which is obj) and

// adding the first parameter passed, which is 5.

 


Function toString()