-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass-constructor.js
More file actions
52 lines (36 loc) · 1.06 KB
/
Copy pathclass-constructor.js
File metadata and controls
52 lines (36 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
//let's understand more about class constructors and static in JavaScript.
// All of this comes after or in ES6
class User {
constructor(name, email, password) {
this.name = name;
this.email = email;
this.password = password;
return this
}
changeUserName(){
return `${this.name.toUpperCase()}`
}
setUserName() {
return `${this.name.trim()}.codingdev`
}
}
const userOne = new User("Muhammad Shakir", "shakir@xyz", "hajks222");
console.log(userOne);
// console.log(userOne.changeUserName());
// console.log(userOne.setUserName());
// behind the scenes
function user(name, email, password) {
this.name = name;
this.password = password;
this.email = email;
return this;
}
user.prototype.changeUserName = function(){
return `${this.name.toUpperCase()}`;
}
user.prototype.setUserName = function () {
return `${this.name.trim()}.codingdev`;
}
const userTwo = new user("Haris", "Harisxyz@go", "asdasdf");
console.log(userTwo);
console.log(userTwo.setUserName());