-
Notifications
You must be signed in to change notification settings - Fork 0
/
arrow-function.html
68 lines (57 loc) · 1.64 KB
/
arrow-function.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<script type="text/javascript">
console.log('-------- without arrow function----------');
let studentList = function (students) {
console.log(students);
};
studentList(['A', 'B', 'c']);
console.log('-------- with arrow function----------');
let studentList1 = (students) => {
console.log(students);
};
studentList1(['A', 'B', 'c', 'D']);
console.log('-------- map function----------');
let list = ['apple', 'banana', 'charry'];
list.map(function (item) {
console.log(item);
});
console.log('-------- map function with arrow----------');
let list1 = ['apple', 'banana', 'charry'];
list1.map((item) => {
console.log(item);
});
//Understanding this in arrow functions
let person = {
first: 'Angie',
hobbies: ['bike', 'motor', 'ski'],
printHobbies: function () {
this.hobbies.forEach(function (hobby) {
let string = `${this.first} like to ${hobby}`;
console.log(string);
});
},
};
person.printHobbies();
let person1 = {
first: 'Angie',
hobbies: ['bike', 'motor', 'ski'],
printHobbies: function () {
let _this = this;
this.hobbies.forEach(function (hobby) {
let string = `${_this.first} like to ${hobby}`;
console.log(string);
});
},
};
person1.printHobbies();
let person2 = {
first: 'Angie',
hobbies: ['bike', 'motor', 'ski'],
printHobbies: function () {
this.hobbies.forEach((hobby) => {
let string = `${this.first} like to ${hobby}`;
console.log(string);
});
},
};
person2.printHobbies();
</script>