Object.freeze()

彻底冻结一个对象

var constantize = (obj) => {
	Object.freeze(obj);
	Object.keys(obj).forEach( (key, i) => {
		if(typeof obj[key] === 'object') {
			contantize(obj[key]);
			}
	});
	};

或者

var constantize = (obj) => {
	Object.freeze(obj);
	Object.values(obj).forEach( (value, i) => {
		if(typeof value === 'object') {
			contantize(value);
			}
		});
	};

你可能感兴趣的:(JS)