zoukankan      html  css  js  c++  java
  • 深克隆

    //定义函数 获取对象的构造函数(类)名
        function getObjectClass(obj) {
          return Object.prototype.toString.call(obj).slice(8, -1)
        }
        function deepClone(obj) {
          if (getObjectClass(obj) === "Object") {
            var res = {}  
          } else if (getObjectClass(obj) === "Array") {
            var res = [];
          } else {
            return obj
          }

          for (var i in obj) {
            res[i] = deepClone(obj[i]);
          }
          return res;
        }

  • 相关阅读:
    暑假学习
    暑假学习
    暑假学习
    暑假学习
    暑假学习
    经验教训+总结
    NT 时刻
    联赛模拟测试 17
    联赛模拟测试 16
    联赛模拟测试 15
  • 原文地址:https://www.cnblogs.com/wangsai-666/p/12038243.html
Copyright © 2011-2022 走看看