对象的彻底冻结freeze

    const person = {
      name: "JonSnow",
      child: {
        name: "Cercei"
      }
    };
    const completelyFreeze = obj => {
      Object.freeze(obj);
      Object.keys(obj).forEach(key => {
        if (typeof obj[key] === "object") {
          completelyFreeze(obj[key]);
        }
      });
    };
    completelyFreeze(person);

你可能感兴趣的:(对象的彻底冻结freeze)