-
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
78deb5b
commit 3be65bb
Showing
2 changed files
with
21 additions
and
5 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 |
---|---|---|
@@ -1,11 +1,23 @@ | ||
class Counter {} | ||
|
||
Counter.prototype.count = 0; | ||
Counter.prototype.increment = function () { | ||
this.count += 1; | ||
}; | ||
|
||
const counter1 = new Counter(); | ||
|
||
const counter2 = new Counter(); | ||
|
||
const counter1Prototype = Reflect.getPrototypeOf(counter1); | ||
const counter2Prototype = Reflect.getPrototypeOf(counter2); | ||
console.log(`Prototype has: ${Object.keys(Reflect.getPrototypeOf(counter1))}`); | ||
console.log(`Before increment, instance has: ${Object.keys(counter1)}`); | ||
|
||
console.log(counter1.count); | ||
console.log(counter2.count); | ||
|
||
counter1.increment(); | ||
|
||
console.log(`After increment. instance has: ${Object.keys(counter1)}`); | ||
|
||
console.log(counter1 === counter2); // false | ||
console.log(counter1Prototype === counter2Prototype); // true | ||
// Objects are different, but they share their prototypes | ||
console.log(counter1.count); | ||
console.log(counter2.count); |
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