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
| const player1 = { | |
| name: 'Sagiv', | |
| } | |
| player1.userName = 'sag1v'; | |
| player1['score'] = 700; | |
| player1.setScore = function(newScore) { | |
| player1.score = newScore; | |
| } |
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
| const player1 = { | |
| userName: 'sag1v', | |
| score: '700', | |
| setScore(newScore){ | |
| player1.score = newScore; | |
| } | |
| } |
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
| class Player { | |
| constructor(userName, score) { | |
| this.userName = userName; | |
| this.score = score; | |
| } | |
| setScore(newScore) { | |
| this.score = newScore; | |
| } | |
| } |
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
| class Player { | |
| constructor(userName, score) { | |
| this.userName = userName; | |
| this.score = score; | |
| } | |
| setScore(newScore) { | |
| this.score = newScore; | |
| } | |
| } |
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
| { | |
| userName: 'sag1v', | |
| score: '700' | |
| } |
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
| player1: { | |
| userName: 'sag1v', | |
| score: 700, | |
| __proto__: playerFunctions | |
| } | |
| player2: { | |
| userName: 'sarah', | |
| score: 900, | |
| __proto__: playerFunctions |
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
| Player { | |
| userName: "sag1v", | |
| score: 700, | |
| __proto__: Player.prototype { | |
| setScore: ƒ | |
| } | |
| } | |
| PaidPlayer { | |
| userName: "sarah", |
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 Player(username, score){ | |
| if(!(this instanceof Player)){ | |
| throw new Error('Player must be called with new') | |
| } | |
| // ES2015 syntax | |
| if(!new.target){ | |
| throw new Error('Player must be called with new') | |
| } |
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 Player(userName, score){ | |
| this.userName = userName; | |
| this.score = score; | |
| } | |
| Player.prototype.setScore = function(newScore){ | |
| this.score = newScore; | |
| } | |
| const player1 = new Player('sag1v', 700); |
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
| const playerFunctions = { | |
| setScore(newScore) { | |
| this.score = newScore; | |
| } | |
| } | |
| function createPlayer(userName, score) { | |
| const newPlayer = Object.create(playerFunctions); | |
| newPlayer.userName = userName; | |
| newPlayer.score = score; |