"r"是什么?当您查看骨干对象时,chrome开发工具的含义是什么? [英] What does the "r" mean in chrome dev tools when you're looking at a Backbone Object?

查看:45
本文介绍了"r"是什么?当您查看骨干对象时,chrome开发工具的含义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习骨干,并使用chrome devl工具查看浏览器中的对象. "r"是什么意思?

I'm learning backbone and using chrome devl tools to look at objects in my browser. What does the 'r' mean?

推荐答案

这是用于创建模型对象的构造函数的名称.但是,在这种情况下,骨干网代码已缩小.

It's the name of the constructor used to create the model object. However in this case the Backbone code has been minified.

如果您创建基本Model类的实例,则将这样记录日志:

If you create an instance of the base Model class it will be logged like this:

如果您查看主干源代码,则可以找到构造函数定义:

If you look at the Backbone source code you can find the constructor definition:

var Model = Backbone.Model = function(attributes, options) {

但是,如果您的代码被压缩,则该对象将显示如下:

However, if your code is compressed the object will instead show up like this:

在您的情况下,您正在使用Backbone的扩展机制来创建一个从基本Model继承的新模型类型.

In your case you're using Backbone's extend mechanism to create a new model type that inherits from the base Model.

未压缩,将显示如下:

同样,我们可以查看Backbone源代码以了解原因:

Again, we can look at the Backbone source code to understand why:

var extend = function(protoProps, staticProps) {
    // ...
    child.prototype.constructor = child;
    // ...
    return child
}

您会看到,创建新模型类型时,Chrome无法访问您要用于模型的名称.相反,它会尽力从变量名称中推断出正确的名称.

You can see that when the new model type is created Chrome doesn't have access to the name you want to use for the model. Instead it tries to do its best to infer the correct name from the variable names.

然后,在压缩后,您将获得在控制台中看到的单字符类名称:

And then, after compression, you get the single-character class name that you are seeing in the console:

这篇关于"r"是什么?当您查看骨干对象时,chrome开发工具的含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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