Created
February 22, 2015 16:18
-
-
Save jamc92/4b3885da23ae0cfdda0c to your computer and use it in GitHub Desktop.
JS - Function as a Parameter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--(method - filter())--> | |
<!DOCTYPE html> | |
<html> | |
<head lang="en"> | |
<meta charset="UTF-8"> | |
<title>Function as a Parameter - Lambdas</title> | |
<script src="main.js"></script> | |
</head> | |
<body> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Si no existe la variable, crear el arreglo | |
if (!NSLambdas) { | |
var NSLambdas = {}; | |
} | |
//Se le asigna a la variable creada el metodo filtro, para filtrar segun la regla de la funcion | |
NSLambdas.filter = function() { | |
//Se asigna el arreglo y sus elementos | |
var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | |
//Se asigna resultado de la funcion del filtro para que retorne el modulus del elemento por 2 | |
var odd = numbers.filter(function(element) { | |
return element % 2; | |
}); | |
//Imprime el contenido de la variable odd | |
console.log(odd); | |
}; | |
//Se crea la funcion para que al momento de cargar la pagina, la ventana llame al evento al cargar | |
//la funcion que hace el llamado al filtro de la variable NSLambdas | |
(function() { | |
window.addEventListener("load", function() { | |
NSLambdas.filter(); | |
}); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment