-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Aaron Nguyen
committed
Feb 7, 2022
1 parent
08c98de
commit 78deb5b
Showing
2 changed files
with
27 additions
and
0 deletions.
There are no files selected for viewing
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
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 |
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
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` |