I have'nt found any clear explanation on that in Google's console api reference, but I was curious to understand and here are my conclusions.
This is a simplified version of what's happening in jQuery, keeping only what's interesting in the question's context.
var jQuery = function() {
return new jQuery.fn.init();
};
jQuery.fn = jQuery.prototype = {
init: function() {
return this;
}
};
var j = jQuery();
console.log(j);
>> jQuery.fn.jQuery.init {}
When logging an object in the console, Chrome displays some kind of internal identifier which depends on how the object was set in the code. It is some kind of representation of the object's structure in the namespace where it was created. If you were to invert fn and prototype (i.e jQuery.prototype = jQuery.fn = {...
) it would print out as jQuery.fn.init
instead of jQuery.fn.jQuery.init
.
Strangely, if you were to add array-like properties (just like jQuery does), it would display the object differently in the console. I have tried removing/adding properties, and it seems that adding a length
property with a Number type value and a splice
property with a Function type value, you get the object displayed in the console like an array (with square brackets).
var jQuery = function() {
return new jQuery.fn.init();
};
jQuery.fn = jQuery.prototype = {
init: function() {
return this;
},
length: 0,
splice: function(){}
};
jQuery.fn.init.prototype = jQuery.fn;
var j = jQuery();
console.log(j);
>> [init: function, splice: function]
So, I think we should not pay much attention to the way Chrome prints out an object's "name" or how it formats it...