0.2.1 • Published 5 years ago

safer-class v0.2.1

Weekly downloads
3
License
ISC
Repository
github
Last release
5 years ago

safer-class

Social Media Photo by freestocks.org on Unsplash

Build Status Coverage Status WebReflection status

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.