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 | |
| } | |
| Player { | |
| userName: "sarah", | |
| score: 900, | |
| __proto__: Player.prototype |
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
| const playerFunctions = { | |
| setScore(newScore) { | |
| this.score = newScore; | |
| } | |
| } | |
| function createPlayer(userName, score) { | |
| const newPlayer = Object.create(playerFunctions); | |
| newPlayer.userName = userName; | |
| newPlayer.score = score; |
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 { | |
| 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 double(num) { | |
| return num * 2; | |
| } | |
| double.someProp = 'Hi there!'; | |
| double(5); // 10 | |
| double.someProp // Hi there! | |
| double.prototype // {} |
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 PaidPlayer(userName, score, balance) { | |
| this.balance = balance; | |
| /* we are calling "Player" without the "new" operator | |
| but we use the "call" method, | |
| which allows us to explicitly pass a ref for "this". | |
| Now the "Player" function will mutate "this" | |
| and will populate it with the relevant properties */ | |
| Player.call(this, userName, score); | |
| } |
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, | |
| setScore: ƒ | |
| } | |
| { | |
| userName: 'sarah', | |
| score: 900, | |
| setScore: ƒ |
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
| double.toString() |
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.call(this, userName, score) |
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 = Object.create(null) | |
| player1.userName = 'sag1v'; | |
| player1['score'] = 700; | |
| player1.setScore = function(newScore) { | |
| player1.score = newScore; | |
| } |