Overwrite PouchDB constructor from plugin

Viewed 17

I want to overwrite the PouchDB constructor and I figured out a way to do it, but it doesn't work within a plugin. This code works:

let PouchDB = require("pouchdb");
let originalPrototype = PouchDB.prototype;
let originalConstructor = PouchDB.prototype.constructor;
PouchDB = function (...args) {
  console.log("Constructor Overwrittern");
  originalConstructor.call(this, ...args);
};
PouchDB.prototype = originalPrototype;
let db = new PouchDB("db");

But this code doesn't work:

let PouchDB = require("pouchdb");
PouchDB.plugin(function (Pouch) {
  let originalPrototype = Pouch.prototype;
  let originalConstructor = Pouch.prototype.constructor;
  Pouch = function (...args) {
    console.log("Constructor Overwrittern");
    originalConstructor.call(this, ...args);
  };
  Pouch.prototype = originalPrototype;
});
let db = new PouchDB("db");

Any ideas why?

0 Answers
Related