Created
May 27, 2020 17:38
-
-
Save gaearon/a25fd42a1e6b4cc24851978df0a36571 to your computer and use it in GitHub Desktop.
Beneath Classes: Prototypes
This file contains 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 Spiderman { | |
lookOut() { | |
alert('My Spider-Sense is tingling.'); | |
} | |
} | |
let miles = new Spiderman(); | |
miles.lookOut(); |
This file contains 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 Spiderman { | |
let SpidermanPrototype = { | |
lookOut() { | |
alert('My Spider-Sense is tingling.'); | |
} | |
}; | |
// let miles = new Spiderman(); | |
let miles = { __proto__: SpidermanPrototype }; | |
miles.lookOut(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This
someFunction.prototype.__proto__ === everyObjectProto; // true
can be changed tosomeFunction.prototype === everyObjectProto; // false
for clarity