Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
little coffeescript class quiz
class Person
info: {}
setName: (name) -> @info.name = name
justin = new Person()
justin.setName "justin"
paul = new Person()
@justinjmoses

This comment has been minimized.

Copy link
Owner Author

justinjmoses commented Aug 24, 2012

what does paul.name return?

  • {} or
  • {name: "justin"}
@michaelficarra

This comment has been minimized.

Copy link

michaelficarra commented Aug 24, 2012

{name: "justin"}, obviously. You've shared it on the prototype. If you wanted an own-property, you'd need to make a new one in the constructor for each instance. Basic understanding of the JS prototype system would have told you that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.