Skip to content

Instantly share code, notes, and snippets.

@yoko
Created February 10, 2009 13:59
Show Gist options
  • Save yoko/61394 to your computer and use it in GitHub Desktop.
Save yoko/61394 to your computer and use it in GitHub Desktop.
(function($) {
$.override = function(target, copy) {
$.each(copy, function f(k, v) {
if (v === null)
delete target[k];
else if (typeof v == 'object') {
target[k] = target[k] || ($.isArray(v) ? [] : {});
var _target = target;
var _copy = copy;
target = target[k];
copy = copy[k];
$.each(v, f);
target = _target;
copy = _copy;
}
else
target[k] = v;
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment