Javascript Classes
<script>
class User {
constructor(name, lastName, email, password) {
this.userName = name;
this.lastName = lastName;
this.email = email;
this.password = password;
}
sayHello() {
console.log(`hello, my name is ${this.userName}`);
}
getProfile() {
console.log(
`my Profile ${this.lastName} ${this.email} ${this.password}`
);
}
changePassword(newPassword, currentPassword) {
if (currentPassword == this.password) {
this.password = newPassword;
} else {
console.log("Can't Change the Password");
}
}
}
const sexyUser = new User("rorin", "jang", "rorin@kakao.com", "1234");
sexyUser.getProfile();
console.log(sexyUser.password);
sexyUser.changePassword("hello", "1234");
console.log(sexyUser.password);
sexyUser.changePassword("hello", "1234");
console.log(sexyUser.password); //"can't change the password" password is "hello"
class Admin extends User {
deletWebsite() {
console.log("deleting hole webSite...");
}
}
const sexyAdmin = new Admin("mango", "kim", "mango@naver.com", "mango");
sexyAdmin.deletWebsite();
console.log(sexyAdmin.email);
</script>