How do I monkey patch an object's constructor function?

You seem to want to do something like:

Constructor.prototype.oldTag = Constructor.prototype.tag;

Constructor.prototype.tag = function() {/* whatever */};

Now all instances get the new tag method and you can still call oldTag if you want (or put it back).

Or perhaps you want to do something like:

var oldConstructor = Constructor;

 var Constructor = function () { /* new constructor */ };
 Constructor.prototype = oldConstructor.prototype;

So now you have a new constructor with all the old methods. Or do both the above. Just use plain English to say what you want to do.


The cleaner way is not monkey patching the constructor: put the constructor logic in a separate init method and monkey patch / inherit that instead.

function Constructor(){
    this.init();
}
Constructor.prototype.init = function(){ /*...*/ };

You can also consider building objects with a builder function

function make_fancy_obj(){
    var obj = new Constructor();
    obj.foo = 'bar';
    return obj;
}