class User{
constructor(username,email){
this.username= username,
this.email = email,
this.score = 0
}
a = [this.email] // showing undefined
login(){
console.log(`you have logged in ${this.username}`);
return this;
}
logout(){
console.log(`you have logout ${this.username}`);
return this;
}
incScore() {
this.score +=1;
console.log(`The ${this.username} have scored ${this.score}`)
return this;
}
}
const userOne = new User('mdvenkatesh','mdv@gmail.com');
console.log(userOne)
// but check it here
class User{
constructor(username,email){
this.username= username,
this.email = email,
this.score = 0
}
a = [this] // showing the complete user data
login(){
console.log(`you have logged in ${this.username}`);
return this;
}
logout(){
console.log(`you have logout ${this.username}`);
return this;
}
incScore() {
this.score +=1;
console.log(`The ${this.username} have scored ${this.score}`)
return this;
}
}
After my class i declared a array a and intilized with the this keyword o/p
a: Array(1) 0: User {a: Array(1), username: "mdvenkatesh", email: "mdv@gmail.com", score: 0} length: 1 __proto__: Array(0) email: "mdv@gmail.com" score: 0
username: "mdvenkatesh"
but when i tryed with user.name it is showing undefined the o/p is following
User {a: Array(1), username: "mdvenkatesh", email: "mdv@gmail.com", score: 0}
a: [undefined]
email: "mdv@gmail.com"
score: 0
username: "mdvenkatesh"
__proto__: Object
i cantunderstand why you may thing why schould even intilize a varable outside method i want to know how a is treated here i am thinking it is proprtey of the class (plese correct me if i am wrong )
2)why this.username is showing undefined when user is show the data plese help me to know