deep-freeze
Just a small function to freeze the entire object avoiding mutability.
Use
npm install deep-freezer
; let person = firstName: 'name' lastName: 'lastName'; ;
Handle Errors
To throw error when you try to mutate a frozen object, just use the deep-freezer in strict mode.
'use strict' ; let person = firstName: 'name' lastName: 'lastName'; ;
Examples
More examples could be find at example folder.
///Throwing Errors.'use strict' ; let person = firstName: 'name' lastName: 'lastName'; personfirstName = 'New Name'; //==> this line will throw an error. ;
OR
///Ignoring the errors, but still keeping the object frozen.; let person = firstName: 'name' lastName: 'lastName'; personfirstName = 'New Name'; //==> this line will be ignored. ;
Test
npm t