Last active
August 29, 2015 14:11
-
-
Save joshblack/a5dc4b01278afe02d8b5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function User(username) { | |
const secretPasswordKey = Symbol('password'); | |
this.username = username; | |
this.setPassword = function setPassword(password) { | |
this[secretPasswordKey] = password; | |
}; | |
this.authenticate = function authenticate(attempt) { | |
return attempt === this[secretPasswordKey]; | |
}; | |
} | |
let u = new User('jbfr'); | |
u.setPassword('myPassword'); | |
console.log(u['secretPasswordKey']); // null | |
console.log(u[Symbol('secretPasswordKey')]); // null | |
console.log(u.authenticate('badPassword')); // false | |
console.log(u.authenticate('myPassword')); // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment