Object.assign

  1. let testObj = {
  2. a:[1,2,4],
  3. b:{
  4. name:'ls',
  5. school:['huf','yelu'],
  6. parent:{
  7. father:'lili',
  8. mother:'xixi'
  9. }
  10. },
  11. c:function() {
  12. alert(this.b.name)
  13. }
  14. }
  15. let newObj = Object.assign(testObj);
  16. newObj.b.parent.mother = 'qinghua';
  17. newObj.a[0] = 4;
  18. console.log(testObj.b.parent.mother);//qinghua
  19. console.log(testObj.a[0])//
  20. console.log(newObj.c);//ƒ () {alert(this.b.name)}

数组和对象两个引用的是同一块内存

序列/反序列

  1. let testObj = {
  2. a:[1,2,4],
  3. b:{
  4. name:'ls',
  5. school:['huf','yelu'],
  6. parent:{
  7. father:'lili',
  8. mother:'xixi'
  9. }
  10. },
  11. c:function() {
  12. alert(this.b.name)
  13. }
  14. }
  15. let newObj = JSON.parse(JSON.stringify(testObj));
  16. newObj.b.parent.mother = 'qinghua';
  17. newObj.a[0] = 4;
  18. console.log(testObj.b.parent.mother);//xixi
  19. console.log(testObj.a[0])//
  20. console.log(newObj.c);//undefined

数组和对象引用的不是同一块内存,但是函数克隆失败

Object.assign和序列/反序列的更多相关文章

  1. Json序列反序列类型处理帮助类

    Json序列反序列类型处理帮助类. JSON反序列化 JSON序列化 将Json序列化的时间由/Date(1294499956278+0800)转为字符串 将时间字符串转为Json时间 using S ...

  2. Object.assign()

    https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/assign 说明 Ob ...

  3. Object.assign方法复制或合并对象

    Object.assign() 方法可以把任意多个的源对象自身的可枚举属性拷贝给目标对象,然后返回目标对象 var obj = { a: 1 }; var copy = Object.assign({ ...

  4. Object.assign()方法

    对象的扩展 1.ES6中,对象的属性和方法可简写:对象的属性值可不写,前提是属性名已经声明: var name = "zhangsan"; "; var obj = { ...

  5. 微信不支持Object.assign

    微信不支持Object.assign,让我Vue怎么用QAQ... 解决方法: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Refe ...

  6. object.assign()方法的使用

    地址:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/assign

  7. [Javascript] Object.assign()

    Best Pratices for Object.assign: http://www.cnblogs.com/Answer1215/p/5096746.html Object.assign() ca ...

  8. [Redux] Avoiding Object Mutations with Object.assign() and ...spread

    Learn how to use Object.assign() and the spread operator proposed for ES7 to avoid mutating objects. ...

  9. [ES6] Object.assign (with defaults value object)

    function spinner(target, options = {}){ let defaults = { message: "Please wait", spinningS ...

随机推荐

  1. nyoj_524_A-B Problem_201312012035

    A-B Problem 时间限制:1000 ms  |           内存限制:65535 KB 难度:3   描述 A+B问题早已经被大家所熟知了,是不是很无聊呢?现在大家来做一下A-B吧. ...

  2. hdu_hpu第八次周赛_1002 大菲波数_201310270958

    大菲波数 Time Limit : 1000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submissi ...

  3. POJ 3061 Subsequence 尺取

    Subsequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14698   Accepted: 6205 Desc ...

  4. G - Power Strings

    Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc&quo ...

  5. Spring MVC-表单(Form)标签-文件上传(File Upload)示例(转载实践)

    以下内容翻译自:https://www.tutorialspoint.com/springmvc/springmvc_upload.htm 说明:示例基于Spring MVC 4.1.6. 以下示例显 ...

  6. iOS开发使用Unwind Segue进行返回

    我们在之前的一篇博客中谈到怎样使用dismissViewControllerAnimation()的方法在iOS中返回,如今我们有一个更为方便的方法来实现界面跳转之后的返回操作.使用的是Unwind ...

  7. SIPp web frontend(2)

    SIP VoIP 測试交流群: 323827101 欢迎大家转载.为保留作者成果,转载请注明出处.http://blog.csdn.net/netluoriver,有些文件在资源中也能够下载.假设你没 ...

  8. Android EditText得到和失去焦点时,自定义处理内容

    当android的Edittext得到/失去焦点时,需要自定义一些处理内容时,需要对EditText对象的Focus进行监听处理. 在Activity中,做以下处理: 1.取得EditText对象. ...

  9. jsp 常用标签的使用

    jsp中定义实体bean<jsp:useBean id="clu" class="cn.domain.CacluBean"></jsp:use ...

  10. hdu 3037Saving Beans(卢卡斯定理)

    Saving Beans Saving Beans Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...