Ver Mensaje Individual
  #1 (permalink)  
Antiguo 03/07/2009, 03:48
Avatar de Legoltaz
Legoltaz
 
Fecha de Ingreso: agosto-2008
Mensajes: 325
Antigüedad: 16 años, 5 meses
Puntos: 6
Devolver una función más de un valor

Tengo esta duda: ¿Cómo podría hacer para que una función devuelva más de un valor para que los reciba otra función?

He intentado esto, pero no me funciona :

Código JavaScript:
Ver original
  1. function setValues(){
  2. var title = prompt("Title:");
  3. var title2 = prompt("2nd title:");
  4. return [title,title2];
  5. }
  6. var [t,t2] = setValues();
  7. alert("1st title: "+t+";2nd title: "+t2);

También he probado de esta forma, pero sólo me devuelve el segundo valor (title2) y el primero me lo asigna como undefined:

Código JavaScript:
Ver original
  1. function setValues(){
  2. var title = prompt("Title:");
  3. var title2 = prompt("2nd title:");
  4. return title,title2;
  5. }
  6. var t,t2 = setValues();
  7. alert("1st title: "+t+";2nd title: "+t2);