Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I've implemented something similar in the same manner (over-riding `new`). The original idea came from here: http://backstage.soundcloud.com/2012/06/building-the-next-so...

One implementation detail I ran into is how to detect dupes. When you have Backbone Models, this is easy: every model has an `id`. But say you want to apply this same singleton behavior to a Backbone Collection, which don't have natively have `id`s. I saw two options:

1. Assign an `id` to the collection when instantiated (could just be a string, so that you can force a singleton only when you desire it).

2. De-dupe based on `instanceof` checks. The downside here is you always get a singleton even if you might want a one-off instance of a collection.

Are there any other options? Can your Identiy Map handle collections?



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: