Is there a way to test whether an object "is a" Backbone.Model in my unit tests?
backbone.js, javascript
Solution
How about using `instanceof`:
console.log(yourObject instanceof Backbone.Model);
The instanceof operator tests whether an object has in its prototype chain the prototype property of a constructor.
Problem
As part of my unit tests (using QUnit) for a backbone project, I test some collection manipulation functions that return arrays of backbone models. Is there a way to directly test (for sanity's sake) whether the objects in my array extend Backbone.Model or should I just do a duck type check (and if so, how, and on which unique attribute, for example)? Since there is no real "Class" construct in javascript, `typeof` obviously won't do the trick here. I could see this being useful in other tests down the road for my Collections, or to check that things are instances of my specific Backbone classes, etc.