You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since node-constants is using Object.defineProperty, properties of objects constantified by node-constants can be modified. Is this expected behavior? If isn't, you can use Object.freeze to make objects unmodifiable.
"use strict";letdefine=require("node-constants")(global);define("objectConstant",{value: 1});console.log("Initial: ",objectConstant.value);// 1try{objectConstant={value: 100};/*Cannot do this, since `objectConstant` is not writable.*/}catch(cannot){console.error(cannot);}console.log("After `objectConstant = {value: 100};`: ",objectConstant.value);// 1objectConstant.value=2;// But this is able.console.log("After `objectConstant.value = 2;`: ",objectConstant.value);// 2Object.freeze(objectConstant);try{objectConstant.value=10;}catch(cannot){console.error(cannot);}console.log("After freezing the object & `objectConstant.value = 10;`: ",objectConstant.value);// 2
The text was updated successfully, but these errors were encountered:
Since
node-constants
is usingObject.defineProperty
, properties of objects constantified bynode-constants
can be modified. Is this expected behavior? If isn't, you can useObject.freeze
to make objects unmodifiable.The text was updated successfully, but these errors were encountered: