Fix issue with collection model being a function

Per http://backbonejs.org/#Collection-model, the `model` attribute of a collection can be a function, however, if you do this, using `add`/`set` with a model that has an `idAttribute` other than `id` will cause that to be `undefined` and thus the collection will never find a matching model to what you passed in and behave unexpectedly.

It'll wipe your collection, and re-create new models with an incorrect `id` as it'll default to `id` being the `idAttribute`, thereby breaking your application completely.

This fixes this issue by invoking the function and getting the `idAttribute`, falling back to `id` if not defined.

Also moving the `idAttribute` lookup outside of the loop for performance.