-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatic-prop.js
More file actions
33 lines (25 loc) · 908 Bytes
/
static-prop.js
File metadata and controls
33 lines (25 loc) · 908 Bytes
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
class User {
constructor(username) {
this.username = username
}
logMe() {
console.log(`USERNAME IS : ${this.username}`);
}
static createId() {
let randomID = parseInt(Math.random() * 100 + 1);
console.log(`${this.username} your unique ID is : ${randomID}`);
}
}
const newUser = new User("Shakir");
newUser.createId();
// this method generate a new id for me every time i call this method but if don't wana do this so just
// use static keyword which will not allow any other object that is instanciate from this object to use it
// lets see if a class inherit by user class can access of createId or not
class Teacher extends User {
constructor(username, email) {
super(username)
this.email = email
}
}
const teacherOne = new Teacher("NotionChamp", "Btyewise.com");
teacherOne.createId(); // this is not a function