How to get a model model of the base model?

Now I am studying the highway . And I have such a problem: can I get type backbone model . The trunk has a typeof function in javascript or instanceof in java . For instance:

 getModelTypeot: function(model) { // return model type } 
+6
source share
1 answer

In JavaScript, every object has a link to its constructor (the function that was used to create the object). It is available as obj.constructor .

If you have a Backbone.js model that is extended with Backbone.Model this way: var YourModel = Backbone.Model.extend({}); , you can create an object using new : var yourModel = new YourModel(); .

Then you can use yourModel.constructor :

 yourModel.constructor === YourModel // true 

Or instanceof :

 yourModel instanceof YourModel // true yourModel instanceof Backbone.Model // true 
+7
source

All Articles