问题
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