201612020940——《Javascript深拷贝》

  //对象深拷贝
 function  deepcopy (obj,newobj) {
                 var newobj = newobj || {};
                 for (var i in obj) {
                     if (typeof obj[i] == "object") {
                         newobj[i]=(obj[i].constructor === Array)?[]:{};
                         deepcopy(obj[i],newobj[i]);
                     }else{
                         newobj[i]=obj[i];
                     }
                 }
                        return newobj;
             };

学习Js是一条长路,不能仅仅限于网页动效

posted @ 2016-12-02 09:42  Coca-code  阅读(109)  评论(0编辑  收藏  举报