Ver Mensaje Individual
  #1 (permalink)  
Antiguo 26/07/2014, 20:57
Avatar de ClubIce
ClubIce
 
Fecha de Ingreso: diciembre-2008
Mensajes: 216
Antigüedad: 15 años, 4 meses
Puntos: 2
Problema con closure

Hola, tengo un problema, y es que estoy intentan hacer algo como esto:

Código Javascript:
Ver original
  1. var funcs = [];
  2. for (var i = 0; i<3: i++) {
  3.   funcs.push(function () {
  4.     var index = i;
  5.     console.log(index);
  6.   });
  7. }
  8.  
  9. for (var i in funcs) {
  10.   funcs[i]()
  11. }
  12.  
  13. // El anterior codigo imprime: 3 3 3 3, mientras que yo quiero que imprima 0 1 2 3

Realmente no se como hacer que hago lo que quiero.