Visualising Prototypes
Video
JavaScript Notes
JavaScript
let log = console.log;
let myObj = {}; // same as: new Object()
log(myObj.constructor); // function Object(){}
log(myObj.__proto__ === myObj.constructor.prototype); // {}
function Cat() {
//constructor for kitty
}
let kitty = new Cat();
log(kitty.__proto__ === Cat.prototype); // Cat{}
log(kitty.__proto__.__proto__ === Object.prototype); // {}
log(Object.prototype.__proto__); // null
function Animal() {}
Object.setPrototypeOf(Cat.prototype, Animal.prototype);
log(kitty.__proto__); // Cat{}
log(kitty.__proto__.__proto__); // Animal {}
log(kitty.__proto__.__proto__.__proto__); // {}
log(kitty.__proto__.__proto__.__proto__.__proto__); // null
Feedback
Submit and view feedback