Que payasada la mia!!! en fin... no habia leido sobre prototipos y estaba jugando ...
En fin.. esto es mas util para clarificar el poder de "memorizacion" de los closures:
Código Javascript
:
Ver original<script type="text/javascript">
/*
Capacidad de memorizacion de variables locales de closures
@author: Pablo Bozzolo (italico76)
*/
f = function(){
if (typeof contador == "undefined"){
contador=1;
console.log('Hi, this is the '+contador+'st you\'ve visted me');
}else{
contador++
console.log('Hi, this is the '+contador+'nd you\'ve visted me');
}
};
f();
f();
f();
</script>
Imprime en la consola:
Cita: Hi, this is the 1st you've visted me
Hi, this is the 2nd you've visted me
Hi, this is the 3nd you've visted me