contents   index   previous   next

Function call()

syntax:[thisObj[, arguments[, ...]]])


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


   // Uses argument list,arg1,arg2)


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



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.



Function(), Function.apply()



// The following code:


var myFunction = new Function("arg", 

                     "return this.a + arg");

var obj = { a:4 }; 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()