Skip to content

Instantly share code, notes, and snippets.

@veryeasily
Created March 5, 2014 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save veryeasily/9372176 to your computer and use it in GitHub Desktop.
Save veryeasily/9372176 to your computer and use it in GitHub Desktop.
Never modify properties of object pointers on your prototype in javascript, or you break things higher up in the chain. I also show a good workaround
### BAD WAY ###
class Animal
Animal.prototype.foo = {bar: "baz"}
class Dog extends Animal
fred = new Dog()
fred.foo.bar = "broken"
alert(Animal.prototype.foo.bar)
# => "broken"
### WORKAROUND ###
class Animal
Animal.prototype.foo = {bar: "baz"}
class Dog extends Animal
fred = new Dog()
fred.foo = {}
fred.foo.bar = "broken"
alert(Animal.prototype.foo.bar)
# => "baz"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment