For example:
Object.defineProperty(Promise.prototype, 'onFinally', {
get: () => {},
writable: false,
});
or
Object.freeze(Promise.prototype);
These examples aren’t work, is there a working way?
For example:
Object.defineProperty(Promise.prototype, 'onFinally', {
get: () => {},
writable: false,
});
or
Object.freeze(Promise.prototype);
These examples aren’t work, is there a working way?
2
Answers
You can call
Object.freeze()
on theString.prototype
, but if you try to redefine a method, it will silently be ignored.Note that freezing an Object’s prototype is ill-advised.
Actually the example you provided works:
You just have to call it in the correct order.