Is there a way to make an “Object.frozen” object throw warnings when an attempt is made to change it?
问题 I use Object.freeze as a means to prevent myself from breaking my own rules. I would like Object.freeze to speak to me when I try to make a bad assignment. However, Object.freeze simply makes the assignments silently fail! For example, if I do /* * Frozen singleton object "foo". */ var foo = (function() { var me = {}; me.bar = 1; if (Object.freeze) { Object.freeze(me); } return me; })(); foo.bar = 2; console.log(foo.bar); the console will log "1", but I won't know that I ever made a bad