获取骨干示范实例的模型/类名 [英] Get a Backbone Model instance's model/class name
问题描述
由于主干模型的实例,我怎么能知道阶级这个实例的(这么说)?
例如:
类汽车扩展Backbone.Modelmycar =新车()
和我需要的是:
mycar.modelName#=> '汽车'
这是一般的问题,我想。我要建议一些在这里提到的选项(<一个href=\"http://stackoverflow.com/questions/332422/how-do-i-get-the-name-of-an-objects-type-in-javascript\">How我是否能够得到在JavaScript中对象的类型的名称?),但我是有第一个选项的问题。你总是可以延长你所有的车型有返回的名称为模型的功能,但我能理解为什么您可能会发现不尽如人意。
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'
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.
这篇关于获取骨干示范实例的模型/类名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!