How do I retrieve the model name for a backbone.js model instance?
For example:
var Topic = Backbone.Model.extend({
})
var topic = new Topic({ type: 'question' })
var doSomethingWithTopic = function(topic) {
// check if passed in topic is of type Topic
// something like topic.constructor.name === 'Topic'
}
doSomethingWithTopic(topic)
I realize I may be blurring the line between a backbone.js model and a class, so I am open to other ways of going about this if needed.
js Get model is used to get the value of an attribute on a model. Syntax: model. get(attribute)
Backbone. Backbone has been around for a long time, but it's still under steady and regular development. It's a good choice if you want a flexible JavaScript framework with a simple model for representing data and getting it into views.
Model contains dynamic data and its logic. It performs various types of action on the data like validation, conversion, computed properties, access control etc. 1. It extends Backbone.
Use the instanceof
operator.
var doSomethingWithTopic = function(topic) {
if( topic instanceof Topic ) {
// do something with topic
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With