# 🏅 5/5 (三) 每日任務 Day 8
###### tags: `Vue 直播班 - 2021 夏季班`
題目 (使用 CodePen 作答)
---
請同學修改程式碼以符合以下要求 (只可以修改註解範圍內的程式碼):
step1. 將 town 的內容複製到 townData。
step2. 將 Ming, Rick 兩個物件加入到 townData.resident 中
>`townData === town` 的結果須為 false。
**參考觀念:**
[1. JavaScript 展開與其餘](https://wcc723.github.io/javascript/2017/12/24/javascript-spread-operator/)
[2. Object.assign()](https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
[3. 重新認識 JavaScript: Day 05 JavaScript 是「傳值」或「傳址」?](https://ithelp.ithome.com.tw/articles/10191057)
```js=
let town = {
name: '真心鎮',
resident: []
}
let townData = {};
let Ming = { name: '小明', age: 16 };
let Rick = { name: '瑞克', age: 21 };
/*程式碼修改處 (可以更改 function 規則)*/
function addResident(obj, res1, res2) {
}
/*程式碼修改處*/
addResident(town, Ming, Rick);
console.log(townData === town); // 結果須為 false
```
回報流程
---
請同學依照下圖教學觀看解答、回報答案:

回報格式如下圖,請在「回報區」使用註解回報答案 (為了統計人數,請同學依序加上「報數」)

<!-- 解答
// 解法一
function addResident(obj, res1, res2) {
townData = {...obj};
townData.resident.push(res1);
townData.resident.push(res2);
}
// 解法二
function addResident(obj, res1, res2) {
townData = Object.assign({}, obj);
townData.resident.push(res1, res2); // push 可推入多個值
}
// 解法三
function addResident(obj, ...res) {
townData = Object.assign({}, obj);
townData.resident.push(...res);
}
-->
回報區
---
<!-- 1: Alpha
codepen: https://codepen.io/alphatero/pen/ZEezMEN
-->
<!-- 2: Vic
codepen: https://codepen.io/hsuan333/pen/MWpgqgR
-->
<!-- 3: Sean Liu
codepen: https://codepen.io/LuckyTiger/pen/xxqKaxw
-->
<!-- 4: Lina Chen
codepen: https://codepen.io/LinaChen/pen/OJpLoyv
-->
<!-- 5: Harold
codepen: https://codepen.io/YuWin0805/pen/mdWbGEq
-->
<!-- 6: Jordan Tseng
codepen: https://codepen.io/jordan-ttc-design/pen/KKWPxmY?editors=1011
-->
<!-- 7: Ethan
codepen: https://codepen.io/blazer030/pen/bGqbxLO
-->
<!-- 8: leolee
codepen: https://codepen.io/nekorice/pen/yLMBxom
-->
<!-- 9: Yi Chieh
codepen: https://codepen.io/Yi-Chieh/pen/vYxBzbj
-->
<!-- 10: yijun
codepen: https://codepen.io/sandy3068/pen/eYvOPOd
-->
<!-- 11: 陳sam
codepen: https://codepen.io/euldpliv/pen/YzZKORa?editors=0001
-->
<!-- 12: youting
codepen: https://codepen.io/youtingluo/pen/poezxvg?editors=0012
-->
<!-- 13: Joe Kuo
codepen: https://codepen.io/alertislow/pen/BaWBqye?editors=0011
-->
<!-- 14: Li Shang
codepen: https://codepen.io/li-shang/pen/wvJwEOZ
-->
<!-- 15: Alysa Chan
codepen: https://codepen.io/alysachan/pen/XWMrxNg?editors=0011
-->
<!-- 16: Jack
codepen: https://codepen.io/yxzzktmb/pen/xxqKyRp?editors=0012
-->
<!-- 17: Chou Allen
codepen: https://codepen.io/eepson123tw/pen/OJpLBjL?editors=1111
-->
<!-- 18: Olga
codepen: https://codepen.io/heavenbird_0221/pen/vYxBVRM?editors=1111
-->
<!-- 19: Dah
codepen: https://codepen.io/hua0124/pen/YzZKJJM
-->
<!-- 20: Iven
codepen: https://codepen.io/rtorihnk/pen/OJpLBry?editors=1011
-->
<!-- 21: Chiang
codepen: https://codepen.io/ChiangJ/pen/LYWPXNo?editors=0011
-->
<!-- 22: Alivn Chu
codepen: https://codepen.io/wave99487chu/pen/GRWKwrZ
-->
<!-- 23: 圈圈
codepen: https://codepen.io/wei-the-lessful/pen/gOmYQWw
-->
<!-- 24: Sec
codepen: https://codepen.io/Sentiments/pen/oNZvQNR?editors=1111
-->
<!-- 25: Larry
codepen: https://codepen.io/manpower0708/pen/mdWbQXr?editors=1111
-->
<!-- 26: Ray
codepen: https://codepen.io/posidomcode/pen/YzZKRxy
-->
<!-- 27: peter.chem1024
codepen: https://codepen.io/JIAN-RONG/pen/BaWBGpp?editors=0012
-->
<!-- 28: SONYKO
codepen: https://codepen.io/s_syoujyo/pen/MWpgzxL?editors=0011
-->
<!-- 29: Jemma
codepen: https://codepen.io/Jemma9/pen/dyvbQKY?editors=0011
-->
<!--
報數 30 : Valerie
codepen: https://codepen.io/vicky-chang/pen/qBrWLaa?editors=0012
-->
<!--
報數 31: YOYO
codepen: https://codepen.io/lumedkle/pen/GRWKPVw?editors=0011
-->
<!-- 報數 32: Erica
Codepen: https://codepen.io/ericadu/pen/ExWYrPv
-->
<!-- 報數 33: Tori
Codepen: https://codepen.io/hayen/pen/poRYxEQ?editors=0012
-->
<!-- 報數 34: RitaHunag
Codepen:
https://codepen.io/Rita-Rossweisse/pen/mdWbaPB?editors=0011
-->
<!-- 報數 35: 阿倫
CodePen:https://codepen.io/jason5125122/pen/BaWBMQX
-->
<!-- 報數 36: WuJungHan
CodePen:https://codepen.io/JungHanWu/pen/qBrWgoy?editors=0012
-->
<!-- 報數 37: Carrie
CodePen: https://codepen.io/echocarriet/pen/PopYLxj
-->
<!-- 報數 38: 家齊
Codepen: https://codepen.io/jacky298/pen/mdWbgBX
-->
<!-- 報數 39: Ted Kuo
Codepen: https://codepen.io/TedKuo/pen/xxqKNKL
-->
<!-- 報數 40: Echo
Codepen: https://codepen.io/bcq65958/pen/QWpLRaN?editors=1112
-->
<!-- 報數 41: Eric-小偉哥
Codepen: https://codepen.io/ericLoveDesign/pen/gOmYJEb?editors=1111
-->
<!-- 報數 42: Wendy Li
Codepen: https://codepen.io/rockayumitw/pen/jOBONQV?editors=1011
-->
<!-- 報數 42: jimmyFang
Codepen: https://codepen.io/pohxiqqo/pen/PopooQW?editors=1011
-->
<!-- 報數 43: Jasmin
Codepen: https://codepen.io/thejasmin/pen/oNYqKOM
-->
<!-- 報數 44: Alicia Lo
Codepen: https://codepen.io/dkcyhyre/pen/eYvYYZr
-->
<!-- 報數 45: Izumi 泉
Codepen: https://codepen.io/izumi-dev/pen/gOgEZzM
-->
<!-- 報數 46: Jrhung-Tsai
Codepen: https://codepen.io/Araytsai/pen/jOBOPVb
-->
<!-- 報數 47: moitw
Codepen:https://codepen.io/tsuifei/pen/RwpwPdz
-->
<!-- 報數 48: Ed Huang
Codepen:https://codepen.io/yide1986/pen/KKWKdpv?editors=0002
-->
<!-- 報數 49: Amber
Codepen:https://codepen.io/amberTing/pen/YzZzqER?editors=1012
-->
<!-- 報數 50: 小魚
Codepen:https://codepen.io/jarvis1993/pen/Rwpwgaw?editors=0010
-->
<!-- 報數51: Wei
CodePen:https://codepen.io/uwhhiaxx/pen/OJpLYpe?editors=0012
-->
<!-- 報數52: Amanda Chiang
CodePen:https://codepen.io/cym199922/pen/PopoRGZ?editors=0011
-->
<!-- 報數53: Josh Fang
答案
function addResident(obj, res1, res2) {
townData = {...town};
townData.resident.push(res1, res2);
}
-->
<!-- 報數54: JessieCheng
CodePen:https://codepen.io/JessieMosbi/pen/wvJvEom?editors=1011
-->
<!-- 報數55: Fred Chang
CodePen:https://codepen.io/fred8196/pen/jOBOXEK?editors=1111
-->
<!-- 報數56: Echo Hui
CodePen: https://codepen.io/echohuiecho/pen/wvJBMzp?editors=0011
-->
<!-- 報數57: Yiren
CodePen: https://codepen.io/Yiren_Liou/pen/RwpNrro?editors=0012
-->
<!-- 報數58: shoppingq
CodePen: https://codepen.io/shoppingq/pen/yLMyOXY
-->
<!-- 報數59: Chiayu
CodePen: https://codepen.io/c85771029/pen/yLMyVve
-->
<!-- 報數60: Stacey Huang
CodePen:https://codepen.io/staceyhuang/pen/VwpYydP?editors=1011
-->
<!-- 報數61: 李重炫
CodePen:https://codepen.io/otherway1123/pen/VwpYqZY?editors=1011
-->
<!-- 報數62: Tofu Tseng
每日任務回饋:
1.Object.assign(obj) 與 Object.assign({}, obj) 的差異?因為 console.log 出來都相同,但是最終的結果,一個是 true,一個是 false。
2.有看上方的解答,會需要在 function(...res) 這樣寫的情況,目前想到的是:
a.無法控制傳入的參數有多少的時候
b....res 可以用來驗證避免傳入非定義好的參數
CodePen:https://codepen.io/Tofutseng/pen/ZEeYVvP?editors=0011
-->
<!-- 報數63: 涂阿銘
CodePen:https://codepen.io/asd40441/pen/abJzMZY?editors=0011
-->
<!-- 報數 64: Jay
Codepen: https://codepen.io/jayredk/pen/PopqqEy?editors=1011
-->
<!-- 報數 65: twoz
Codepen: https://codepen.io/twoz/pen/xxqwbpN?editors=0012
-->
<!-- 報數 66: Carol
Codepen: https://codepen.io/taonong/pen/qBrOjBX
-->
<!-- 報數 67:田
codePen: https://codepen.io/ccyy915/pen/dyvMPqE
-->
<!-- 報數 68: Andrew Chi
codePen: https://codepen.io/wheresandrew/pen/ExWgbLa
-->
<!-- 報數 69: kevinhes
codepen:
https://codepen.io/dwpwdpad/pen/NWpbdBY?editors=0011
-->
<!-- 報數 70: Emily Hsi
codepen:
https://codepen.io/EmilyHsi/pen/wvJoLoJ
-->
<!-- 報數 71: MM
codepen:
https://codepen.io/MINN3/pen/JjWGmjQ
-->
<!-- 報數 72: Butters
codepen:
https://codepen.io/Butterscode/pen/bGqWYrV
-->
<!-- 報數 7.: WA
codepen:
https://codepen.io/ldddl/pen/oNWvpaV?editors=0010
-->