实现当对象下的属性又是一个对象的时候,怎么来防止该对象下这个对象的属性被改变
Object.defineProperty(Object, 'freezePolyfill', { value: function(obj) { var i; for (i in obj) { if (obj.hasOwnProperty(i)) { if(typeof(obj[i])==='object'){ Object.freezePolyfill(obj[i]); }else{ Object.defineProperty(obj, i, { writable: false }); } } } Object.seal(obj); } }); const xiaoming = { age: 14, name: '小明', obj: { a: 1 } }; Object.freezePolyfill(xiaoming);