浅拷贝,只能拷贝一层对象,针对对象的嵌套无法解决

    1. array.slice
    1. var numbers = [1,2,3]
    2. var new_numbers = numbers.slice();
    1. array.concat
    1. var strings = ['a', 'b', 'c']
    2. var new_strings = strings.concat();
    1. Object.assign
    1. var person = {name: 'garen', age: 18};
    2. var new_person = Object.assign({}, person);
    1. 展开运算符
    1. var fruits = ['apple', 'banana', 'orange'];
    2. var new_fruits = [...fruits];
    1. 自己实现shadowCopy
    1. function shadowCopy(target) {
    2. if(typeof target !== null && typeof target === 'object') {
    3. let cloneTarget = Array.isArray(target) ? []: {};
    4. for (let prop in target) {
    5. if(target.hasOwnProperty(prop)) {
    6. cloneTarget[prop] = target[prop]
    7. }
    8. }
    9. return cloneTarget;
    10. } else {
    11. return target;
    12. }
    13. }