📜  在 javascript 代码示例中克隆一个对象

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

代码示例6
//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;
}