How to copy/clone a hash/object in JQuery?

前端 未结 6 2149
既然无缘
既然无缘 2021-02-05 00:52

I have a simple object (or hash) in Javascript:

var settings = {
  link: \'http://example.com\',
  photo: \'http://photos.com/me.jpg\'
};

I nee

6条回答
  •  悲&欢浪女
    2021-02-05 01:26

    Underscore.js also has an extend function if you are not using jQuery:

    extend _.extend(destination, *sources) Copy all of the properties in the source objects over to the destination object, and return the destination object. It's in-order, so the last source will override properties of the same name in previous arguments.

    _.extend({name: 'moe'}, {age: 50});
    => {name: 'moe', age: 50}
    

提交回复
热议问题