标签云

微信群

扫码加入我们

WeChat QR Code

Possible Duplicate:What is the most efficient way to clone a JavaScript object?How to clone js object with out reference like these:{ ID: _docEl,Index: next,DocName: _el}Any ideas?


Note too that this isn't one-size-fits-all - this is unlikely to do anything useful for built-in objects like DOM nodes where you'd want to use cloneNode() method, etc.

2019年06月19日35分42秒

obj.i will not work, you will access to the "i" property literally, you need to use the bracket notation, e.g. obj[i]

2019年06月19日35分42秒

CMS: thanks, I've fixed it now.

2019年06月19日35分42秒

This does not seem right. cloneObject({ name: null }) => {"name":{}}

2019年06月19日35分42秒

Niyaz: Thanks, I added a fix.

2019年06月19日35分42秒

Ew, eval()! Not sure this would work either, unless obj has a meaningful toString() method.

2019年06月19日35分42秒

would that not return a reference?

2019年06月19日35分42秒