-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlearn_javascript.js
More file actions
125 lines (115 loc) · 2.86 KB
/
learn_javascript.js
File metadata and controls
125 lines (115 loc) · 2.86 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
function getR(){
return Promise.all([Promise.resolve(true),Promise.reject(true)]).then(()=>{
const a = 3;
return a}).catch((error)=>{
const err = error;
return err;
})
}
function callGetR(){
getR().then((res)=>{console.log(res)}).catch((error)=>{console.log(error)})
console.log(5);
}
callGetR()
//Output
//5
// true
function learnReCatch(){
try {
if(1 !==2){
throw "1 not equal to 2";
} }catch(error){
return error;
}
}
function catchError(){
try {
learnReCatch();
}
catch(error){
console.log(error);
}
}
catchError();
//Output
//undefined
function learnReCatch(){
try {
if(1 !==2){
throw "1 not equal to 2";
} }catch(error){
throw error;
}
}
function catchError(){
try {
learnReCatch();
}
catch(error){
console.log(error);
}
}
catchError();
//Output
// 1 not equal to 2
//19 march
// inheritance example
function Employee() {
this.name = '';
this.dept = 'general';
}
function Manager() {
Employee.call(this);
this.reports = [];
}
undefined
let aman = new Manager();
aman
Manager {name: "", dept: "general", reports: Array(0)}name: ""dept: "general"reports: []__proto__: Objectconstructor: ƒ Manager()length: 0name: "Manager"arguments: nullcaller: nullprototype: {constructor: ƒ}__proto__: ƒ ()[[FunctionLocation]]: VM2846:6[[Scopes]]: Scopes[2]0: Script {aman: Manager}aman: Manager {name: "", dept: "general", reports: Array(0)}1: Global {parent: Window, opener: null, top: Window, length: 0, frames: Window, …}__proto__: Object
Manager
ƒ Manager() {
Employee.call(this);
this.reports = [];
}
Manager.prototype = Object.create(Employee.prototype);
Manager.prototype.constructor = Manager;
ƒ Manager() {
Employee.call(this);
this.reports = [];
}
Manager
ƒ Manager() {
Employee.call(this);
this.reports = [];
}
function WorkerBee() {
Employee.call(this);
this.projects = [];
}
undefined
WorkerBee
ƒ WorkerBee() {
Employee.call(this);
this.projects = [];
}
WorkerBee.prototype
{constructor: ƒ}constructor: ƒ WorkerBee()length: 0name: "WorkerBee"arguments: nullcaller: nullprototype: {constructor: ƒ}constructor: ƒ WorkerBee()__proto__: Object__proto__: ƒ ()[[FunctionLocation]]: VM2992:1[[Scopes]]: Scopes[2]__proto__: Object
Object.getPrototypeOf(WorkerBee)
ƒ () { [native code] }
Object.getPrototypeOf(WorkerBee).constructor
ƒ Function() { [native code] }
WorkerBee.prototype = Object.create(Employee.prototype);
WorkerBee.prototype.constructor = WorkerBee;
ƒ WorkerBee() {
Employee.call(this);
this.projects = [];
}
WorkerBee
ƒ WorkerBee() {
Employee.call(this);
this.projects = [];
}
Object.getPrototypeOf(WorkerBee)
ƒ () { [native code] }
WorkerBee.prototype
Employee {constructor: ƒ}constructor: ƒ WorkerBee()length: 0name: "WorkerBee"arguments: nullcaller: nullprototype: Employee {constructor: ƒ}__proto__: ƒ ()[[FunctionLocation]]: VM2992:1[[Scopes]]: Scopes[2]__proto__: Object