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
document.documentElement.childNodes[0].innerHTML = ''; | |
var pres = document.getElementsByTagName('PRE'); | |
for(var j = 0, len = pres.length; j<len;j++) { | |
var sty= pres[j].style; | |
sty.border='1px solid black'; | |
sty.padding='8px'; | |
sty.marginLeft='32px'; | |
} | |
var df = document.createDocumentFragment(); |
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
// FUNCIONES AUXILIARES | |
/* | |
* La siguiente función cuenta las propiedades | |
* (tanto propias como hereradas) de un objeto | |
*/ | |
function contarPropiedades(obj) { | |
var recuento = 0; | |
for (propiedad in obj) recuento ++; |
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
/* | |
* El siguiente patrón | |
* | |
* function foo(param) { | |
* param = param || valor_por_defecto | |
* ... | |
* | |
* no representa ningún riesgo de cara al rendimiento. | |
* | |
* Con ECMAScript 5 tenemos la posibilidad |
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
Function.prototype.memorizaParametro = function(parametro) { | |
var funcionSobreLaQueSeEjecuto_memorizaParametro = this; | |
return function() { | |
var argsArray = Array.prototype.slice.call(arguments,1); //Menos el primero | |
argsArray.unshift(parametro); | |
return funcionSobreLaQueSeEjecuto_memorizaParametro.apply(this,argsArray); | |
} | |
} | |
//Primer ejemplo: uso puramente funcional |
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
Function.prototype.memorizaParametro = function(parametro) { | |
var funcionSobreLaQueSeEjecuto_memorizaParametro = this; | |
return function() { | |
var argsArray = Array.prototype.slice.call(arguments,0);//Convertimos en array | |
argsArray.unshift(parametro); | |
return funcionSobreLaQueSeEjecuto_memorizaParametro.apply(this,argsArray); | |
} | |
} | |
//Primer ejemplo: uso puramente funcional |
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
//Imperative | |
var checkAccessor1 = function(accesor) { | |
var steps = accesor.split('.'); | |
var cursor = steps[0]; | |
var acumulator = cursor; | |
for (var j=1, len = steps.length;j<len;j++) { | |
cursor += '.' + steps[j]; | |
acumulator += ' && ' + cursor; | |
} |
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
function crearSaludo(array) { | |
var resultado = []; | |
for (var j=0, len = array.length; j<len; j++) { | |
var nombre = array[j]; | |
resultado.push(function(){ | |
console.log("Hola " + nombre); | |
}); | |
} | |
return resultado; | |
} |
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
/********************************************************************* | |
Solución funcional | |
La más elegante, y ahora todos sabemos ;) | |
*********************************************************************/ | |
function crearSaludos1(array) { | |
return array.map(function(nombre){ |
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
function getMax(a,b) { | |
var r = Math.sqrt(a-b); | |
if (isNaN(r)) return b; | |
else return a; | |
} |
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
/* | |
RECUENTO DE VOTOS PARA | |
http://www.meetup.com/madridjs/pages/Votaci%F3n_para_%22Yo_tambi%E9n_quiero_una_birra%22/ | |
Abre la consola, pega el siguiente código en ella | |
y ejecuta el siguiente código :) | |
Verficado en Firefox a las 14:46 del 2011-09-01 | |
*/ |