💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
### 1.浅拷贝(只拷贝地址) ![](https://box.kancloud.cn/e3503f07b6832f5f58c0da52749a4ff8_532x327.PNG) - 此时改变栈中的任一对象的值,俩者的值都会改变,因为他们的存储地址一样 - 改变复制的对象,原对象也会改变 ``` <script> var obj = { name: "chengchao", age: "20" } cheng = obj cheng.name = "zhang" console.log(cheng, obj) //{name: "zhang", age: "20"} {name: "zhang", age: "20"} </script> ``` ### 2.深拷贝(拷贝值和址)将值放入另一个地址中 ![](https://box.kancloud.cn/1f1b4b3da029822c41514ea5aecb2f70_546x316.PNG) - 此时对象之间属性的改变互不影响 - 改变复制的对象,原对象值不会改变 ``` <script> var obj = { name: "chengchao", age: "20" } cheng = { ...obj } cheng.name = "zhang" console.log(cheng, obj) //{name: "zhang", age: "20"} {name: "chengchao", age: "20"} </script> ``` ## promise解决回调地狱 ``` <script> function getData(url){ const promise = new Promise((resolve,reject)=>{ $.ajax({ url, dataType:"jsonp", success:res=>{ resolve(res) }, error:err=>{ reject(err); } }) }) return promise; } getData("https://api.douban.com/v2/book/search?q=javascript&count=1").then(res=>{ let id = res.books[0].id; return getData(`https://douban.uieee.com/v2/book/${id}`) }).then(res=>{ console.log(res); }) </script> ```