Ver Mensaje Individual
  #4 (permalink)  
Antiguo 10/12/2004, 20:14
Avatar de Prince
Prince
 
Fecha de Ingreso: mayo-2003
Ubicación: DF
Mensajes: 574
Antigüedad: 21 años, 6 meses
Puntos: 1
Ok ok, tuve un error, no se necesitaban "caller" ni "calee" pero ya tengo el ejemplo de como hacerlo.

Posiblemente este sea un buen ejemplo para dejarlo en las FAQ de este foro.

- OVERLOADING A FUNCTION -
Overloading a function normally involves having multiple functions with the same name but with different numbers of parameters. This can be useful in a lot of situations. For example, you could have a function named calculateArea() that calculates the area of a rectangle based on two parameters (the lengths of the sides). But you might also want to have a calculateArea() function that calculates the area on a circle based on a single parameter (the radius). The trouble is that, as we know, ActionScript does not require symmetry between the number of parameters defined for a function and the number of parameters passed to it. That means that you cannot have two functions with the same name -even if they expect different numbers of parameters-.
You can simulate function overloading if you desire by using if statements in the function to check for the number of parameters. The following shows how you can write a function that calculates the area of either a rectangle or a circle depending on the number of parameters it is passed (determined by 'arguments.length'):
Código:
function calculateArea():Number{
  switch(arguments.length){
    case 1:
      var radius:Number = arguments[0];
      return (Math.PI * (radius * radius));
    case 2:
      var a:Number = arguments[0];
      var b:Number = arguments[1];
      return (a * b);
    default:
      return null;
  }
}
Bueno, como podemos ver todo lo controlarás con el array 'arguments', en cual controla, dentro de la función, el número de argumentos que le hemos pasado a esta.

SALUDOS
__________________
- P R I N C E -