-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
47 lines (39 loc) · 1.37 KB
/
index.js
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
(function(context) {
function printUpperCase() {
const self = this;
console.log(self);
self.string = self.string.toUpperCase();
return function() {
console.log(this); // window this
console.log(this.string);
console.log(self.string);
}
}
function printUpperCaseFatArrow() {
console.log(this);
this.string = this.string.toUpperCase();
return () => console.log(this.string);
}
function demo() {
console.log('\n\nARROW FUNCTIONS');
printUpperCase.call({ string: 'Hello John Doe' })();
printUpperCaseFatArrow.call({ string: 'Hello John Doe' })();
const person = {
firstName: 'John',
lastName: 'Doe',
printNameFatArrow: () => `${this.firstName} ${this.lastName}`,
printNameRegular: function() { return `${this.firstName} ${this.lastName}` },
printName() { return `${this.firstName} ${this.lastName}` },
}
console.log(person.printNameFatArrow());
console.log(person.printNameFatArrow.bind(person)());
console.log(person.printNameRegular());
console.log(person.printName());
// remember, Arrow functions
// 1. cannot be used for Generators,
// 2. do not get arguments object,
// 3. cannot be used as constructors,
// 4. call(), apply(), and bind() will not change the value of this
};
(context || this).demoLibs['arrow-func'] = demo;
})(window);