The cosmetics of what the Chrome console shows you seem to be determined by:
- the
name property of the constructor function, or
- the variable name that the constructor function is initially assigned to (if
name is not set).
Case #1:
var ClassA = function ClassB() {};
new ClassA();
// reports a `ClassB` object
The constructor function has its name property set to ClassB, so that's what Chrome reports. A function's name is only settable at definition time, so function funcName(){} sets the name, whereas func=function(){}; f.name='funcName'; does not.
Case 2:
var ClassA = function() {};
ClassB = ClassA;
new ClassB();
// reports a `ClassA` object
The constructor was initially assigned to ClassA, so that name seems to be burned into the constructor function, even if it is used under another variable alias. In fact, doing delete window.ClassA does not stop newly constructed objects from reporting themselves as ClassA objects:
var ClassA = function() {};
ClassB = ClassA;
delete window.ClassA;
new ClassB();
// still reports a `ClassA` object
// even though `ClassA` is no longer a defined variable name
This is what is happening in your "dynamically defined" case. The initial window[type] = function() {}; line is permanently marking that constructor's resulting object to identify as type "anonymous function that's a property of window".
Note that these console cosmetics will not affect the functionality of your program, as all object/prototype functionality still works as expected.
window.Animalwindow.(anonymous function).