//////////////// classes in javascript //////////////////
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 User1(username , email , password ){
this.username = username ;
this.email = email ;
this.password = password ;
}
User1.prototype.encryptPassword = function() {
return `${this.password} abc`
}
User1.prototype.changeusername = function() {
return `${this.username.toUpperCase()}abc`
}
const tea = new User1 ("tea" , " tea@gmail" , "123" )
console.log(tea.encryptPassword() );
console.log(tea.changeusername() );
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter