title: JavaScript better way to modify function prototype
body: <p>I wish to create a constructor of constructors.
  Relating to this thread : <a href="https://stackoverflow.com/questions/21740787/javascript-build-a-constructor-of-constructors">JavaScript build a constructor of constructors</a>, it seems the only solutions are :</p>
  
  <pre><code>Function.prototype.add = function(name, value) {
      this.prototype[name] = value;
  };
  Function.prototype.remove = function(name) {
      delete this.prototype[name];
  };
  </code></pre>
  
  <p>But I don't want to modify the generic <code>Function</code> prototype... and also :</p>
  
  <pre><code>var A = new ConstBuilder().add('test', function() {
      console.log('test');
  }).getConstructor();
  </code></pre>
  
  <p>But I don't want to have an object wrapper around the constructor itself.</p>
  
  <p>The problem is that generally constructors creates new objects, inheriting methods from the constructor prototype. What I'm trying to do is to instanciates functions instead of objects, but the only way to modify a function prototype property is this to modify its <code>__proto__</code> property :</p>
  
  <pre><code>var constructorPrototype = {
      add : function(name, value) {
          this.prototype[name] = value ;
      }
  } ;
  
  var ConstBuilder = function() {
      var constructor = function() {} ;
      constructor.prototype = {} ;
      // The only way (?), but quite deprecated...
      constructor.__proto__ = constructorPrototype ;
      return constructor ;
  } ;
  
  // Not working way...
  //ConstBuilder.prototype = constructorPrototype ;
  
  var A = new ConstBuilder() ;
  A.add('test', function() {
      console.log('test') ;
  }) ;
  
  var a = new A() ;
  a.test() ; // "test"
  
  constructorPrototype.remove : function() {
      delete this.prototype[name] ;
  } ;
  
  A.remove('test') ;
  
  a.test() ; // Error: test is not a function.
  </code></pre>
  
  <p><strong>Note</strong> that <code>A.prototype</code> is not <code>A.__proto__</code> <strong>but</strong> <code>A.prototype</code> is <code>(new A).__proto__</code>.</p>
  
  <p>And it works perfectly by modifying <code>__proto__</code>, what a shame.
  I read that Firefox has integrated a "Object.setPrototypeOf()" but it is only experimental.</p>
  
  <p>Would it be another way to do what I wish to do ?</p>