Get a Backbone Model instance#39;s model/class name(获取主干模型实例的模型/类名称)
问题描述
给定一个Backbone模型的实例,我怎么知道这个实例的类"(可以这么说)?
Given an instance of Backbone model, how can I know the "class" (so to speak) of this instance ?
例如:
class Car extends Backbone.Model
mycar = new Car()
而我需要的是:
mycar.modelName # => 'Car'
推荐答案
我认为总体上是有问题的.我打算建议这里提到的一些选项( 如何在 JavaScript 中获取对象类型的名称? ) 但我遇到了第一个选项的问题.您总是可以扩展您的所有模型,使其具有一个返回模型名称"的函数,但我可以理解为什么您会觉得这不太令人满意.
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.
这篇关于获取主干模型实例的模型/类名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:获取主干模型实例的模型/类名称


基础教程推荐
- Karma-Jasmine:如何正确监视 Modal? 2022-01-01
- 有没有办法使用OpenLayers更改OpenStreetMap中某些要素 2022-09-06
- 动态更新多个选择框 2022-01-01
- 悬停时滑动输入并停留几秒钟 2022-01-01
- 角度Apollo设置WatchQuery结果为可用变量 2022-01-01
- 响应更改 div 大小保持纵横比 2022-01-01
- 在for循环中使用setTimeout 2022-01-01
- 我什么时候应该在导入时使用方括号 2022-01-01
- 在 JS 中获取客户端时区(不是 GMT 偏移量) 2022-01-01
- 当用户滚动离开时如何暂停 youtube 嵌入 2022-01-01