Skip to content

Instantly share code, notes, and snippets.

@sag1v
Created November 25, 2019 14:27
Show Gist options
  • Save sag1v/593945fc0813120ac01245fd9cb9038f to your computer and use it in GitHub Desktop.
Save sag1v/593945fc0813120ac01245fd9cb9038f to your computer and use it in GitHub Desktop.
Markdium-JavaScript - The prototype chain in depth
const playerFunctions = {
setScore(newScore) {
this.score = newScore;
}
}
function createPlayer(userName, score) {
const newPlayer = Object.create(playerFunctions);
newPlayer.userName = userName;
newPlayer.score = score;
return newPlayer;
}
const player1 = createPlayer('sag1v', 700);
const player2 = createPlayer('sarah', 900);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment