Created
August 11, 2013 17:09
-
-
Save cleberdantas/6205806 to your computer and use it in GitHub Desktop.
Utilizando algumas funcões utilitarias do underscore.js. Veja mais em: http://underscorejs.org/#utility
This file contains hidden or 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
| //Algumas funcões utilitarias | |
| //Os exemplos funcionarão se o underscore.js estiver presente na página =D | |
| //TIMES - Executa n vezes o que estiver contido no bloco de callback | |
| _.times(2, function(n){ | |
| console.log(n + ' bla bla'); // indice começa em zero | |
| }); | |
| //>> 0 bla bla | |
| //>> 1 bla bla | |
| //RANDOM - Retorna um número aleatório dentro do range passado, incluindo os números passados. | |
| var random = _.random(1, 100) | |
| console.log(random); | |
| //>> qualquer número entre 1 e 100 | |
| //ESCAPE - Faz enconding da string passada | |
| var sentenca = _.escape("Web, etc & tal"); | |
| console.log(sentenca); | |
| //>> Web, etc & tal | |
| //UNESCAPE - Desfaz o enconding da string passada | |
| var sentenca = _.unescape("Web, etc & tal"); | |
| console.log(sentenca); | |
| //>> Web, etc & tal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment