safer-class
v0.2.1
Published
Flattened classes with non configurable fields.
Downloads
9
Maintainers
Readme
safer-class
Social Media Photo by freestocks.org on Unsplash
Flattened classes with non configurable fields (basically safer-object applied to classes and prototypes).
import saferClass from 'safer-class';
const MyPromise = saferClass(class extends Promise {});
// even if inherited methods change
Promise.prototype.then = function () {
throw new Error('Muahahahahaha!');
};
// instances from MyPromise will work like a charm
MyPromise.resolve('whatever').then(() => console.log('all good'));
Remember to eventually freeze the instance if you want extra safety.