How to copy/clone a hash/object in JQuery?
问题 I have a simple object (or hash) in Javascript: var settings = { link: 'http://example.com', photo: 'http://photos.com/me.jpg' }; I need a copy of it. Is there a settings.clone() type method that will give me another object with the same attributes? I'm using jQuery, so happy to use a jQuery utility method if one exists. 回答1: Yes, extend an empty object with the original one; that way, everything will simply be copied: var clone = $.extend({}, settings); Extending some filled object with