In JS, functions and objects are shallow copy (reference address); other, e.g. Boolean, digital and other basic data types are deep copy (reference value).
Deep copy
- JSON.parse (JSON.stringify (src)): This method has limitations if the attribute value is an instance of a class or a function of time, can not copy the correct
- With third-party libraries: JQ's extend (true, result, src1, src2 [, src3]), lodash of cloneDeep (src)
- By means of HTML5 MessageChannel: this approach has limitations, when the attribute value is a function of time, will be given
- Manually make a "perfect" deep copy function: https://godbmw.com/passages/2019-03-18-interview-js-code/
Shallow copy
- ES6 the Object.assign ()
- The operator deconstruction ... ES7