zoukankan      html  css  js  c++  java
  • JS_应用对象的复制

    Object.extend = function(destination, source){   
            for (var property in source) {   
                destination[property] = source[property];   
                }   
            return destination;   
    }
    /*字符串*/
    var string = new String("hello");
    var string1 = string;
    var string2 = string;
    string1 = string1+" world!";
    console.log(string+"|"+string1+"|"+string2);
    /*数组*/
    var arr = [2012,11,12]
    var arr1 = arr.slice(0);
    var arr2 = arr.slice(0);
    arr2.push("4");
    console.log(arr+"|"+arr1+"|"+arr2);
    /*对象*/
    var obj = {name:"shao"};
    var obj1 = Object.extend({},obj);
    var obj2 = Object.extend({},obj);
    obj1.name = "liang";
    console.log(obj.name+"|"+obj1.name+"|"+obj2.name);
  • 相关阅读:
    反射&异常
    成员方法
    继承&多态
    面向对象
    常用模块
    软件目录结构规范
    内置函数
    生产器&迭代器
    装饰器
    函数
  • 原文地址:https://www.cnblogs.com/somesayss/p/2824387.html
Copyright © 2011-2022 走看看