title: Javascript: Allowing "virtual" function in base class to create instance of subclass
body: <p>I have the following object model I want to get working - have been banging my head against the clone bit! Is this possible? I can't seem to get access to the SubClass constructor from within the baseclass without hard coding it.</p>
  
  <p>The code is for a queue of arbitrary operations that all share a lot of common functionality; new operations are created as subclasses that merely override the action() method for operation specific functionality. </p>
  
  <p>Is this possible without overriding the clone() method in each subclass?</p>
  
  <pre><code>/*
  Application specific subclass:
  */
  function SubClass_Operation1()
  {
    BaseOperationClass.apply(this, arguments); // Call inherited constructor
  
    this.action = function()
    {
      this.manager.addToQueue(this.clone({changeValue:1}));
      this.manager.addToQueue(this.clone({changeValue:2}));
      this.manager.addToQueue(this.clone({changeValue:3}));
    }
  }
  SubClass.prototype = new BaseOperationClass;
  
  // More of these defined for each operation
  ...
  
  /*
  Base class containing all common functionality
  */
  function BaseOperationClass(manager)
  {
    this.manager = manager;
  
    // Placeholder for virtual action() function
    this.action = function()
    {
    }
  
    this.clone = function(mods)
    {
      var res = ?????? // Should create exact copy of current SubClass
  
      res.applyModifications(mods);
    }
  
    this.applyModifications(mods)
    {
      ...
    }
  
    // Lots of common functionality 
    ...
  }
  </code></pre>