js深拷贝案例

发布时间 2023-09-03 08:22:17作者: 斯斯20222
<!DOCTYPE html>
<html class="no-js">
    <head>
        <meta charset="utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title></title>
        <meta name="description" content="" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <link rel="stylesheet" href="" />
    </head>
    <style>
        .item{
            color:red;
            background-color: antiquewhite;
            border:1px solid burlywood;
            width:100px;
            height:300px;
        }
    </style>
    <body>
       <div></div>
       
    </body>

    <script>
        const obj={
            uname:'pink',
            age:18,
        }
        const o={}
        function deepCopy(newObj,oldObj){
            for(let k in oldObj){
                newObj[k]=oldObj[k];
            }
        }
        deepCopy(o,obj)
        console.log(o);
    </script>
</html>