-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
188 lines (140 loc) · 3.57 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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
function outer() {
let counter = 0;
function inner(){
counter++;
console.log(counter);
}
return inner
}
// const fn = outer();
// fn();
// fn();
function sum(a,b,c){
return a + b + c;
}
function currySum(fn){
return function(a){
return function(b){
return function(c){
return fn(a,b,c);
}
}
}
}
const curriedSum = currySum(sum);
// console.log(curriedSum(1)(3)(6));
const add1 = curriedSum(1);
const add3 = add1(3);
const add6 = add3(6);
// console.log(add6);
const person = {
name:"walter white",
sayMyName:function(){
console.log(`my name is ${this.name}`);
}
}
// person.sayMyName();
// function sayMyName(){
// console.log(`my name is ${this.name}`);
// }
// sayMyName.call(person);
function Personn(name){
this.name = name;
}
const p1 = new Personn("lara");
const p2 = new Personn("frost");
// console.log(p1.name,p2.name);
// NEID
globalThis.name = "lara";
function sayMyName(){
console.log(`my name is ${this.name}`);
}
// sayMyName();
const arr1 = [1,2,3,4,5,6,7];
function getNewArr(arr){
// const [,,...newArr , ,] = arr;XXXX
const [,,...newArr] = arr;
return newArr;
}
// console.log(getNewArr(arr1));
// function Person(fName,lName){
// this.firstName = fName;
// this.lastName = lName;
// }
// const person1 = new Person("Lara","Croft");
// const person2 = new Person("Frost","Fighter");
// // person1.getFullName = function(){
// // return this.firstName +" "+ this.lastName;
// // }
// Person.prototype.getFullName = function(){
// return this.firstName + ' ' + this.lastName;
// }
// console.log(person1.getFullName());
// console.log(person2.getFullName());
// function Person(fName,lName){
// this.firstName = fName;
// this.lastName = lName;
// }
// Person.prototype.getFullName = function (){
// return `${this.firstName} ${this.lastName}`;
// }
// function SuperHero(fName,lName){
// Person.call(this,fName,lName)
// this.isSuperHero = true;
// }
// SuperHero.prototype = Object.create(Person.prototype);
// SuperHero.prototype.fightCrime = function(){
// console.log("fighting Crime");
// return;
// }
// SuperHero.prototype.constructor = SuperHero;
// const batman = new SuperHero("Bruce","Wayne");
// // console.log(batman.getFullName());
// // console.log(batman.isSuperHero);
// console.log(batman.fightCrime());
class Person {
constructor(fName,lName){
this.firstName = fName;
this.lastName = lName;
}
sayMyName(){
return `${this.firstName} ${this.lastName}`;
}
}
const classP1 = new Person("Bruce","Wayne");
// console.log(classP1.sayMyName());
class SuperHero extends Person {
constructor(fName,lName){
super(fName,lName);
this.isSuperHero = true;
}
fightCrime(){
console.log("fighting crime...")
}
}
const batman = new SuperHero("Bruce","Wayne");
// console.log(batman.sayMyName());
// console.log(batman.isSuperHero);
// console.log(batman.fightCrime());
const obj = {
[Symbol.iterator]:function(){
let step = 0;
const iterator = {
next:function() {
if(step === 0){
step++;
return {value:"hello",done:false}
}
else if(step === 1){
step++;
return {value:"world",done:false}
}
return {value:undefined,done:true}
}
};
return iterator;
}
}
for(const word of obj){
console.log(word);
}