Just as an exercise, I tried monkey-patching the Promise constructor, like so:
const pconstructor = global.Promise;
global.Promise = function (fn1) {
this.foo = 'bar';
pconstructor.call(this,fn1);
};
global.Promise.resolve = pconstructor.resolve;
however, I get an error when I call
Promise.resolve();
=>
TypeError: [object Object] is not a promise
Anyone know how to monkey-patch a constructor like this, properly?
via Alexander Mills
No comments:
Post a Comment