Skip to main content

Here's how extendextend/assignassign works: For each property in source, copy its value as-is to destination. if property values themselves are objects, there is no recursive traversal of their properties. Entire object would be taken from source and set in to destination.

Here's how mergemerge works: For each property in source, check if that property is object itself. If it is then go down recursively and try to map child object properties from source to destination. So essentially we merge object hierarchy from source to destination. While for extendextend/assignassign, it's simple one level copy of properties from source to destination.

Here's simple JSBin that would make this crystal clear: http://jsbin.com/uXaqIMa/2/edit?js,console

Here's more elaborate version that includes array in the example as well: http://jsbin.com/uXaqIMa/1/edit?js,console

Here's how extend/assign works: For each property in source, copy its value as-is to destination. if property values themselves are objects, there is no recursive traversal of their properties. Entire object would be taken from source and set in to destination.

Here's how merge works: For each property in source, check if that property is object itself. If it is then go down recursively and try to map child object properties from source to destination. So essentially we merge object hierarchy from source to destination. While for extend/assign, it's simple one level copy of properties from source to destination.

Here's simple JSBin that would make this crystal clear: http://jsbin.com/uXaqIMa/2/edit?js,console

Here's more elaborate version that includes array in the example as well: http://jsbin.com/uXaqIMa/1/edit?js,console

Here's how extend/assign works: For each property in source, copy its value as-is to destination. if property values themselves are objects, there is no recursive traversal of their properties. Entire object would be taken from source and set in to destination.

Here's how merge works: For each property in source, check if that property is object itself. If it is then go down recursively and try to map child object properties from source to destination. So essentially we merge object hierarchy from source to destination. While for extend/assign, it's simple one level copy of properties from source to destination.

Here's simple JSBin that would make this crystal clear: http://jsbin.com/uXaqIMa/2/edit?js,console

Here's more elaborate version that includes array in the example as well: http://jsbin.com/uXaqIMa/1/edit?js,console

deleted 5 characters in body
Source Link
Shital Shah
  • 69.9k
  • 21
  • 258
  • 202

Here's how extend/assign works: For each property in destinationsource, copy its value as-is to sourcedestination. if property values themselves are objects, there is no recursive traversal of their properties. Entire object would be taken from destinationsource and set in to sourcedestination.

Here's how merge works: For each property in destinationsource, check if that property is object itself. If it is then go down recursively and try to map child object properties from destination to source to destination. So essentially we merge object hierarchy from destination to source to destination. While for extend/assign, it's simple one level copy of properties from destination to source to destination.

Here's simple JSBin that would make this crystal clear: http://jsbin.com/uXaqIMa/2/edit?js,console

Here's more elaborate version that includes array in the example as well: http://jsbin.com/uXaqIMa/1/edit?js,console

Here's how extend/assign works: For each property in destination, copy its value as-is to source. if property values themselves are objects, there is no recursive traversal of their properties. Entire object would be taken from destination and set in to source.

Here's how merge works: For each property in destination, check if that property is object itself. If it is then go down recursively and try to map child object properties from destination to source. So essentially we merge object hierarchy from destination to source. While for extend/assign, it's simple one level copy of properties from destination to source.

Here's simple JSBin that would make this crystal clear: http://jsbin.com/uXaqIMa/2/edit?js,console

Here's more elaborate version that includes array in the example as well: http://jsbin.com/uXaqIMa/1/edit?js,console

Here's how extend/assign works: For each property in source, copy its value as-is to destination. if property values themselves are objects, there is no recursive traversal of their properties. Entire object would be taken from source and set in to destination.

Here's how merge works: For each property in source, check if that property is object itself. If it is then go down recursively and try to map child object properties from source to destination. So essentially we merge object hierarchy from source to destination. While for extend/assign, it's simple one level copy of properties from source to destination.

Here's simple JSBin that would make this crystal clear: http://jsbin.com/uXaqIMa/2/edit?js,console

Here's more elaborate version that includes array in the example as well: http://jsbin.com/uXaqIMa/1/edit?js,console

added 136 characters in body
Source Link
Shital Shah
  • 69.9k
  • 21
  • 258
  • 202

Here's how extend/assign works: For each property in destination, copy its value as-is to source. if property values themselves are objects, there is no recursive traversal of their properties. Entire object would be taken from destination and set in to source.

Here's how merge works: For each property in destination, check if that property is object itself. If it is then go down recursively and try to map child object properties from destination to source. So essentially we merge object hierarchy from destination to source. While for extend/assign, it's simple one level copy of properties from destination to source.

Here's simple JSBin that would make this crystal clear: http://jsbin.com/uXaqIMa/2/edit?js,console

Here's more elaborate version that includes array in the example as well: http://jsbin.com/uXaqIMa/1/edit?js,console

Here's how extend/assign works: For each property in destination, copy its value as-is to source. if property values themselves are objects, there is no recursive traversal of their properties. Entire object would be taken from destination and set in to source.

Here's how merge works: For each property in destination, check if that property is object itself. If it is then go down recursively and try to map child object properties from destination to source. So essentially we merge object hierarchy from destination to source. While for extend/assign, it's simple one level copy of properties from destination to source.

Here's JSBin that would make this clear: http://jsbin.com/uXaqIMa/1/edit?js,console

Here's how extend/assign works: For each property in destination, copy its value as-is to source. if property values themselves are objects, there is no recursive traversal of their properties. Entire object would be taken from destination and set in to source.

Here's how merge works: For each property in destination, check if that property is object itself. If it is then go down recursively and try to map child object properties from destination to source. So essentially we merge object hierarchy from destination to source. While for extend/assign, it's simple one level copy of properties from destination to source.

Here's simple JSBin that would make this crystal clear: http://jsbin.com/uXaqIMa/2/edit?js,console

Here's more elaborate version that includes array in the example as well: http://jsbin.com/uXaqIMa/1/edit?js,console

Source Link
Shital Shah
  • 69.9k
  • 21
  • 258
  • 202
Loading