What does the “r” mean in chrome dev tools when you're looking at a Backbone Object?

心已入冬 提交于 2020-04-30 01:56:41

问题


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


回答1:


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

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:

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

Uncompressed this will show up like this:

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

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

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:



来源:https://stackoverflow.com/questions/36920208/what-does-the-r-mean-in-chrome-dev-tools-when-youre-looking-at-a-backbone-obj

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!