Passing Arguments


One advantage that constructor stealing offers over prototype chaining is the ability to pass arguments into the supertype constructor from within the subtype constructor. Consider the following:

Implementing prototype chaining involves the following code pattern:

			
						
			
			

In this code, the SuperType constructor accepts a single argument, name , which is simply assigned to a property. A value can be passed into the SuperType constructor when called from within the SubType constructor, effectively setting the name property for the SubType instance. To ensure that the SuperType constructor doesn't overwrite those properties, additional properties may be defined on the subtype after the call to the supertype constructor.