-
-
Save dutradotdev/b48670989caaca124bd233f34bd9c9c5 to your computer and use it in GitHub Desktop.
Prototype chain
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
/* | |
navegaremos de construtor a construtor até obter um erro | |
no final na prototype chain | |
*/ | |
var set = new Set(); | |
console.log(set); | |
// [] | |
console.log(set.constructor); | |
// ƒ Set() { [native code] } | |
console.log(set.__proto__.constructor); | |
// ƒ Set() { [native code] } | |
console.log(set.__proto__.__proto__.constructor); | |
// ƒ Object() { [native code] } | |
console.log(set.__proto__.__proto__.__proto__.constructor); | |
// Uncaught TypeError: Cannot read property 'constructor' of null | |
/* | |
Como o temos dois construtores diferentes (Set e Object) | |
podemos dizer que nosso set é uma instância de Set e de Object | |
*/ | |
console.log(set instanceof Set) // true | |
console.log(set instanceof Object) // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment