Created
November 16, 2018 18:55
-
-
Save gisderdube/83260c2d9ffc96aede93defdac4a0e9b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| class Counter { | |
| constructor() { | |
| this.count = 5 | |
| this.add = function() { | |
| this.count++ | |
| } | |
| } | |
| copy() { | |
| const copy = new Counter() | |
| Object.keys(this).forEach(key => { | |
| const value = this[key] | |
| switch(typeof value) { | |
| case 'function': | |
| break | |
| case 'object': | |
| copy[key] = JSON.stringify(JSON.parse(value)) | |
| break | |
| default: | |
| copy[key] = value | |
| break | |
| } | |
| }) | |
| return copy | |
| } | |
| } |
In line no 20, shouldn't the line be JSON.parse(JSON.stringify(value))?
@gisderdube please fix the mistake that @AjaySankar detected.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
Awesome article in medium.
In line no 20, shouldn't the line be JSON.parse(JSON.stringify(value))?