1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>箭头函数实践</title> <style> div { width: 200px; height: 200px; background: #58a; } </style> </head> <body> <div id="ad"></div> <script> let ad = document.getElementById("ad"); ad.addEventListener("click", function() { let self = this; console.log(this); setTimeout(function(){ self.style.background = 'pink'; }, 2000) }); let ad = document.getElementById("ad"); ad.addEventListener("click", function() { setTimeout(() => { console.log(this); this.style.background = 'pink'; }, 2000) });
const arr = [1, 6, 9, 10, 100, 25]; const result = arr.filter(function(item){ if(item % 2 == 0) { return true; } else { return false; } }); const result = arr.filter(item => item % 2 === 0);
console.log(result);
</script> </body>
</html>
|