forked from ti17m006/code-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv22-iife-and-this.js
More file actions
55 lines (39 loc) · 1.06 KB
/
Copy pathv22-iife-and-this.js
File metadata and controls
55 lines (39 loc) · 1.06 KB
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
//
let person = (function (name) {
console.log("This name parameter is private");
return {
getName: function () {
return name;
}
}
})("Adam Smith I");
let personArrow = ((name) => {
console.log("This name parameter is private");
return {
getName: function () {
return name;
}
}
})("Adam Smith I Arrow");
// console.log(person.getName());
// console.log(personArrow.getName());
const PageHandler = {
id: '213',
// this won't work
init: (value) => {
setTimeout(() => this.do(value), 2000); // this.do is not a function
},
// this won't work
do: (type) => {
console.log(`Handling ${type} for ${this.id}`);
},
initFunction: function (value) {
setTimeout(() => this.doFunction(value, this.id), 2000);
},
doFunction: function (a, b) {
console.log(`Handling ${a} for ${b}`);
},
};
PageHandler.initFunction("ABC");
//const myType = () => { };
// const myObject = new myType(); // TypeError: myType is not a constructor