-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2b026a9
commit 3739d94
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// ES6 | ||
|
||
class User { | ||
constructor(username, email, password){ | ||
this.username = username; | ||
this.email = email; | ||
this.password = password | ||
} | ||
|
||
encryptPassword(){ | ||
return `${this.password}abc` | ||
} | ||
changeUsername(){ | ||
return `${this.username.toUpperCase()}` | ||
} | ||
|
||
} | ||
|
||
const chai = new User("chai", "chai@gmail.com", "123") | ||
|
||
console.log(chai.encryptPassword()); | ||
console.log(chai.changeUsername()); | ||
|
||
// behind the scene | ||
|
||
function User(username, email, password){ | ||
this.username = username; | ||
this.email = email; | ||
this.password = password | ||
} | ||
|
||
User.prototype.encryptPassword = function(){ | ||
return `${this.password}abc` | ||
} | ||
User.prototype.changeUsername = function(){ | ||
return `${this.username.toUpperCase()}` | ||
} | ||
|
||
|
||
const tea = new User("tea", "tea@gmail.com", "123") | ||
|
||
console.log(tea.encryptPassword()); | ||
console.log(tea.changeUsername()); |