获取主干模型实例的模型/类名称 [英] Get a Backbone Model instance's model/class name

查看:14
本文介绍了获取主干模型实例的模型/类名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个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.

这篇关于获取主干模型实例的模型/类名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆