I read this trick on the Soundcloud blog: http://backstage.soundcloud.com/2012/06/building-the-next-soundcloud/
You can return an existing object from a javascript constructor to avoid creating a new object.
I'm using this as an identity map - one instance per id. Adapted to Coffeescript and adding a feature
to update the existing class with any new information (me.set(data)
), it looks something like user.coffee.
You have to copy-paste the simple return super
constructor into every child class. Without this the code breaks. Not sure how to solve this issue.