📜  javascript 克隆对象数组 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:46.377000             🧑  作者: Mango

代码示例4
//returns a copy of the object
function clone(obj) {
    if (null == obj || "object" != typeof obj) return obj;
    var copy = obj.constructor();
    for (var attr in obj) {
        if (obj.hasOwnProperty(attr)) copy[attr] = obj[attr];
    }
    return copy;
}