The new operator hard-wires the type of object to be created.


Specify the kinds of objects you'd like to be able to create, build a prototypical instance of that, and create new objects by cloning those prototypes.

Related Patterns


Clients clone() the abstract base class, supplying an optional data type designating the desired subtype. The new operator is abandoned in favor of prototype cloning.


JavaScript uses prototypes extensively for object creation. The object constructor function in JS is the prototype for that object (which can be called with the new operator).


JavaScript has string built-in support for prototypes:

var myprototype = function myprototypeobj(){ = function(){alert("foo");}; = function(){alert("bar");};
var myobj.prototype = myprototype;;; // myobj is created with the methods of myprototype