Skip to content

Commit

Permalink
Start Chapter 8. Using Inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Nguyen committed Feb 7, 2022
1 parent 08c98de commit 78deb5b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
11 changes: 11 additions & 0 deletions 8-using-inheritance/examine-prototype.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Counter {}

const counter1 = new Counter();
const counter2 = new Counter();

const counter1Prototype = Reflect.getPrototypeOf(counter1);
const counter2Prototype = Reflect.getPrototypeOf(counter2);

console.log(counter1 === counter2); // false
console.log(counter1Prototype === counter2Prototype); // true
// Objects are different, but they share their prototypes
16 changes: 16 additions & 0 deletions 8-using-inheritance/using-inheritance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Chapter 8. Using Inheritance

JavaScript implements **prototypal** inheritance

## Understanding Prototypal Inheritance

- Prototypal inheritance is implemented using delegation
- Delegation is better than inheritance
- Instead of relying on base class or superclass, prototypal inheritance relies on an object next in the chain to serve as its base
- Prototypal inheritance is dynamic which allows altering object that serves as the base at runtime
- Base object is called the object's prototype

## Prototype Chain

- Object chaining
- `Reflect.getPrototypeOf`

0 comments on commit 78deb5b

Please sign in to comment.