Skip to content

Instantly share code, notes, and snippets.

@gisderdube
Created November 16, 2018 18:55
Show Gist options
  • Select an option

  • Save gisderdube/83260c2d9ffc96aede93defdac4a0e9b to your computer and use it in GitHub Desktop.

Select an option

Save gisderdube/83260c2d9ffc96aede93defdac4a0e9b to your computer and use it in GitHub Desktop.
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
}
}
@AjaySankar
Copy link

Hi,
Awesome article in medium.
In line no 20, shouldn't the line be JSON.parse(JSON.stringify(value))?

@JuanmaMenendez
Copy link

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