View comments | RSS feed

arguments.callee

Availability

Flash Player 5.

Usage

arguments.callee:Function

Description

Property; refers to the function that is currently being called.

Example

You can use the arguments.callee property to make an anonymous function that is recursive, as shown in the following example:

factorial = function (x:Number) {
   if (x<=1) {
      return 1;
   } else {
      return x*arguments.callee(x-1);
   }
};
trace(factorial(3));  // output: 6

The following example is a named recursive function:

function factorial(x:Number):Number {
   if (x<=1) {
      return 1;
   } else {
      return x*factorial(x-1);
   }
}
trace(factorial(4));  // output: 24

Comments


Nixy said on Sep 15, 2005 at 11:36 AM :
Over 256 level that does not woks. Why.
In this case the number is to big, but I need to create a recursive function. setInterval is not an option.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/mx2004/main_7_2/00001187.html