Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
67
rated 0 times [  68] [ 1]  / answers: 1 / hits: 21340  / 12 Years ago, tue, march 13, 2012, 12:00:00

Given an instance of Backbone model, how can I know the class (so to speak) of this instance ?



For instance:



class Car extends Backbone.Model

mycar = new Car()


And what I need is:



mycar.modelName # => 'Car'

More From » backbone.js

 Answers
8

It's problematic in general, I think. I was going to suggest some of the options mentioned here ( How do I get the name of an object's type in JavaScript? ) but I was having issues with the first option. You could always extend all your models to have a function that returned a name for the model, but I can understand why you might find that less than satisfactory.


[#86874] Monday, March 12, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
devlin

Total Points: 474
Total Questions: 113
Total Answers: 100

Location: Sweden
Member since Fri, Apr 16, 2021
3 Years ago
devlin questions
Tue, Apr 27, 21, 00:00, 3 Years ago
Sat, Oct 31, 20, 00:00, 4 Years ago
Fri, Aug 28, 20, 00:00, 4 Years ago
;