Reputation: 10926
Given a Backbone model or backbone model instance, I would like to get the model's name. For instance:
var p = new Person(); // Person is a BB model.
console.log(p.getNameAsStringOrSomething()); //Prints "Person"
Thats it, pretty simple :D
Upvotes: 0
Views: 563
Reputation: 2613
You can try
model.constructor.name
However, it will not work if you have a minifier like Jammit, the constructor will change after packaging and also on chrome you it might not work
I would suggest you to have a class property then you can get the name by simply using
var obj = model.constructor.propertyName
Upvotes: 1