Prototype Chain
Object.getPrototypeOf(obj) | Get prototype |
obj.__proto__ | Prototype (legacy, avoid) |
obj instanceof Constructor | Prototype chain check |
Object.create(proto) | Create with specific prototype |
Constructor Functions
function Animal(name) { this.name = name; } | Constructor function |
Animal.prototype.speak = function() {} | Add to prototype |
new Animal('dog') | Create instance |
Class Syntax (ES6)
class Animal {
constructor(name) { this.name = name; }
speak() {}
} | Class declaration |
class Dog extends Animal {
speak() { super.speak(); }
} | Inheritance with super |