/
arrow functions.html
43 lines (31 loc) · 1.09 KB
/
arrow functions.html
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
<!DOCTYPE html>
<html>
<head>
<title>Arrow function</title>
</head>
<body>
<script type="text/javascript">
//arrow functions nie posiada this (a dokładnie to określa this leksykalnie, tj. przypisuje wartosc this w zalezcności od tego gdzie występuje, a nie normalnie że this przyposane jest do obiektu, który wywołuje funkcje)
greet = (name, place="home") => {
return `Hello ${name}. Welcome to ${place}`;
}
//jesli funkcja posiada tylko jeden parametr, nie trzeba uzywac nawiasów
greet = name => {
return `Hello ${name}`;
}
//jesli funckja jedyne co robi to zwraca jaka wartosc zapis mozna jeszcze bardziej uproscic
greet = name => `Hello ${name}`
//tablica.forEach(function(element, index){})
//tablica.forEach(element => {})
const arr = ["JavaScript", "Python", "PHP"];
arr.forEach(language => {
console.log(language);
});
//setTimeout(function(){}, 1000 [ms])
//setTimeout(() => {}, 1000) funkcja callback nie ma zadnych argumentow, stad tylko puste nawiasy
setTimeout(() => {
console.log("Times out");
}, 3000);
</script>
</body>
</html>