Created
November 12, 2015 18:09
-
-
Save evaldosantos/0faa27dbe62db835a524 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title></title> | |
</head> | |
<body> | |
<button class="button_">button 1</button> | |
<button>button 2</button> | |
<button class="button_">button 3</button> | |
<script type="text/javascript"> | |
var jQuery = function(elem) { | |
return document.querySelectorAll(elem); | |
}; | |
(function(davide) { | |
/*** com FOR | |
var descricoes = [ | |
'descricao do botao 1', | |
'descricao do botao 2', | |
'descricao do botao 3', | |
]; | |
var buttons = davide('button'); | |
function buttonHandle(i) { | |
return function() { | |
console.log('clicked!', descricoes[i]); | |
}; | |
} | |
for(var i=0; i<buttons.length; i++) { | |
buttons[i].onclick = buttonHandle(i); | |
} | |
console.log(i); | |
*/ | |
// com FOREACH :D :D <3 | |
var descricoes = [ | |
'descricao do botao 1', | |
'descricao do botao 2', | |
'descricao do botao 3', | |
]; | |
[].forEach.call(davide('button'), function(el, idx) { | |
el.onclick = (function buttonHandle(i) { | |
return function() { | |
console.log('clicked!', descricoes[i]); | |
}; | |
})(idx); | |
}) | |
})(jQuery); | |
var myArr = [1,2,3,4,5,6,7,8,9]; | |
/* | |
for(var i=0; i<myArr.length; i++) { | |
console.log(myArr[i]); | |
} | |
*/ | |
/* | |
for(var i=0; i<myArr.length; i++) { | |
myArr[i] = myArr[i]*2; | |
} | |
console.log(myArr) | |
*/ | |
console.log(myArr.map(function(el) { return el*2; })); | |
/* | |
var pares = []; | |
for(var i=0; i<myArr.length; i++) { | |
if(myArr[i]%2==0) { | |
pares.push(myArr[i]) | |
} | |
} | |
console.log(pares); | |
*/ | |
console.log(myArr.filter(function(el){ return el%2==0; })); | |
Array.prototype.sum = function() { | |
return this.reduce(function(soma, el) { | |
soma = soma+el; | |
return soma; | |
}); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment