Skip to content

Instantly share code, notes, and snippets.

@dutradotdev
Created March 18, 2019 11:05
Show Gist options
  • Save dutradotdev/b48670989caaca124bd233f34bd9c9c5 to your computer and use it in GitHub Desktop.
Save dutradotdev/b48670989caaca124bd233f34bd9c9c5 to your computer and use it in GitHub Desktop.
Prototype chain
/*
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