laitimes

30. What is the implementation principle of jQuery's attribute copy, and how to achieve shallow copy?

author:Chi Zi Mu

The jQuery.extend() function is used to merge the contents of one or more objects into the target object.

grammar

$.extend( target [, object1 ] [, objectN ] )

Indicates whether the merge is deep

$.extend( [deep ], target, object1 [, objectN ] )

Note: Passing false for the first parameter is not supported.

30. What is the implementation principle of jQuery's attribute copy, and how to achieve shallow copy?

Deep copy: The deep copy code sets the first argument of the extend function to true: (recursive copy of the object referenced by the original object property) var newObject = $.extend(true, {},oldObject);

Shallow copy: the first argument is not passed in the extend function of the shallow copy code, the default is false (only copy of the original object reference) var newObject = $.extend({}, oldObject);