Advertisement
Javi

jQuery: Funciones parámetros variables

Jul 8th, 2013
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var saludar = function(nombreORepeticiones, mensaje) {             
  2.     mensaje = mensaje || 'Hola';
  3.     if (typeof(nombreORepeticiones) == 'string') {
  4.         _saludarPersona(nombreORepeticiones, mensaje);
  5.     } else {
  6.         _saludarRepeticiones(nombreORepeticiones, mensaje);
  7.     }
  8. }
  9.  
  10. function _saludarPersona(nombre, mensaje) {
  11.     console.log(nombre+ ': ' + mensaje);
  12. }
  13.  
  14. function _saludarRepeticiones(repeticiones, mensaje) {
  15.     for (var i=0; i < repeticiones; i++) {
  16.         console.log(mensaje);
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement