$.extend => update_attributes
jQuery has a built-in update attributes method, I know extend is used to extend fn and jQuery for plugins, but it can also serve as a great way to update attributes on javascript objects. For example:
If you have a object:
x = {
name: 'foobar',
items: ['item1', 'item2']
}
And you persisted the object to a Form, then when the user submits the form, you pull the params in to an object using a plugin like formparams.js
y = $('form').formparams()
Now you want to merge the two objects:
$.extend(true, x, y);
The “true” will perform a deep merge bringing in arrays and nested objects.
As the documentation says, it is not for real extensive merges, but for quick and simple merges, it should work great on the client!