Java Reference
In-Depth Information
All objects have a constructor property that returns the constructor function that cre-
ated it:
red.constructor
<< Dice(sides)
When an object literal is used to create a new object, we can see that in the background the
Object constructor function is being used:
var objectLiteral = {};
<< {}
objectLiteral.constructor;
<< function Object() {
[native code]
}
This can be used to instantiate a copy of an object, without having to reference the actual
constructor function directly. For example, if we wanted to make another instance like the
red dice, but if the name if its constructor was unknown, we could use the following:
var green = new red.constructor(10); // create a new Dice
instance
green.instanceOf Dice
<< true
Search WWH ::




Custom Search