function shadowCopy(a, b){ if(!a || typeof a !== 'object'){ return } if(!b || typeof b !== 'object'){ return } for(var key in b){ if(b.hasOwnProperty(key)){ a[key] = b[key] } } } //var o = [1, 2, 3] // defined new empty arr //var newB = [] //shadowCopy(newB, o) //console.log(newB) //console.log(newB == o) var o = { m: 1, n: { c: 2 } } var newB = {} shadowCopy(newB, o) console.log(newB) console.log(newB == o) // false