Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const config = {};
- config.email = 'email@email.com';
- config.emailOverwrite = true;
- config.overwriteEmails = [
- 'e1@mail.com',
- 'e2@mail.com'
- ];
- const readOnly = (object) => {
- const handler = {
- get: (target, key, receiver) => {
- if (Object(target[key]) !== target[key]){
- return target[key];
- } else {
- return readOnly(target[key]);
- }
- },
- set: (target, key, value, receiver) => {throw new Error('Read Only')}
- }
- return new Proxy(object, handler);
- }
- readOnlyObject = readonly(config);
- readOnlyObject.overwriteEmails.push('test'); // throws
Add Comment
Please, Sign In to add comment