编辑代码

// 深拷贝
const deepCopy = (obj) => {
    var result = Array.isArray(obj) ? [] : {};
    for (var key in obj) {
      if (obj.hasOwnProperty(key)) {
        if (typeof obj[key] === 'object') {
          result[key] = deepCopy(obj[key]);   //递归复制
        } else {
          result[key] = obj[key];
        }
      }
    }
    return result;
}

const obj = {
    a:{
        name: "a"
    } ,
    b:{
        name: "b"
    }
} ;

const pureFunc = ({
    obj ,
    c
}) => {
    const new_obj = deepCopy(obj) ;
    return Object.assign({} , new_obj , {c}) ;
}

const somePureFunc = ({
    obj ,
    c
}) => {
    return Object.assign({} , obj , {c}) ;
} ;

const noPureFunc = ({
    obj ,
    c
}) => {
    obj.c = c ;
    return obj ;
} ;