Ver Mensaje Individual
  #4 (permalink)  
Antiguo 17/09/2009, 14:18
Avatar de David
David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años, 9 meses
Puntos: 839
Respuesta: pequeña duda del tipo: Porque no lo hace?

Debes tener en cuenta el alcance de las variables, no es lo mismo asignar un valor a url en la función showUser (precedida de var) que hacerlo en la función horas (precidada o no de var)

Con este ejemplo creo que quedará claro:
Código Javascript:
Ver original
  1. function funcion1() {
  2.     var url = 'http://test/';
  3.    
  4.     funcion2();
  5.    
  6.     alert(url);
  7. }
  8.  
  9. function funcion2() {
  10.     url = 'http://other/';
  11. }
  12.  
  13. function funcion3() {
  14.     var url = 'http://test/';
  15.    
  16.     url = 'http://other/';
  17.    
  18.     alert(url);
  19. }
  20.  
  21. function funcion4() {
  22.     url = 'http://test/';
  23.    
  24.     funcion2();
  25.    
  26.     alert(url);
  27. }
  28.  
  29. funcion1(); /* http://test/ */
  30. funcion3(); /* http://other/ */
  31. funcion4();  /* http://other/ */
Debes tener en cuenta que no siempre es lo mismo usar var o no al asignar el valor de una variable.
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.