javascript - How to get type backbone model? - Stack Overflow

I am learning backbone now. And I have a problem like this: can I get type backbone model. Backbone hav

I am learning backbone now. And I have a problem like this: can I get type backbone model. Backbone have a function like typeof in javascript or instanceof in java. Like that:

getModelTypeot: function(model) {
    // return model type 
} 

I am learning backbone now. And I have a problem like this: can I get type backbone model. Backbone have a function like typeof in javascript or instanceof in java. Like that:

getModelTypeot: function(model) {
    // return model type 
} 
Share Improve this question edited Mar 7, 2013 at 12:38 Ulug'bek asked Mar 7, 2013 at 12:30 Ulug'bekUlug'bek 2,8326 gold badges34 silver badges62 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

In JavaScript each object has a reference to its constructor (a function that was used to create the object). It's accessible as obj.constructor.

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

Then, you could use yourModel.constructor:

yourModel.constructor === YourModel // true

Or instanceof:

yourModel instanceof YourModel // true
yourModel instanceof Backbone.Model // true

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744941728a4602366.html

相关推荐

  • javascript - How to get type backbone model? - Stack Overflow

    I am learning backbone now. And I have a problem like this: can I get type backbone model. Backbone hav

    1天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信