The function internals are special objects that get assigned to every function. These objects are arguments and this.

Arguments

Arguments are array like objects that get passed to a function. Each argument has a property called callee. The purpose of that property is to point to the function that owns the arguments. The property is frequently used with recursive functions like one in the following example:

function recursiveF(count) {

   if (count <=1 ) break;

   else {

      return count + arguments.callee(count-1);

   }

}

This

The other special object belonging to functions is this. This is a pointer to the object that the function is operating on. It may also be considered as a pointer to the scope in which the function is being executed; for instance if the function is running in the global scope then this refers to the window object.

Observe following example:

function alertFont() {

   alert(this.font);

}

window.font = "serif";

var obj = { font: "Arial" };

alertFont(); // "serif"

obj.alertFont(); // "Arial"

Example

Example of function internals, this and arguments:

 

›› go to examples ››