Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spread 擴展運算符 跟 rest 剩餘運算符是不是可以再多舉一些範例 ? #9

Open
jawayang opened this issue Jun 29, 2016 · 3 comments

Comments

@jawayang
Copy link
Contributor

jawayang commented Jun 29, 2016

投影片
擴展運算符 -> https://hackmd.io/p/S1Jll4LH#/2/6
剩餘運算符 -> https://hackmd.io/p/HJcb_nKf#/1/5

@jawayang
Copy link
Contributor Author

可以搭配一下這篇文章服用
http://cookfront.github.io/2015/06/06/es6-function/

@jawayang
Copy link
Contributor Author

簡單說
rest 就是把參數變成陣列
spread 是把陣列變成參數
可以這樣說嗎?

@jawayang
Copy link
Contributor Author

allen.hsieh :
關於 Rest Parameter,我的理解如下:用於 function 承接參數,由於 js 在函式定義與實際呼叫時,參數傳遞個數可以不同,故要取得非事先定義好的參數必須透過下列兩種方式
(1) 透過 arguments 物件
(2) ES6 可以透過 Rest Parameter

rest 的好處:
(1) rest 是承接剩下尚未定義的參數,arguments object 則是所有實際傳遞的參數都放進去,要取剩餘的部分,要自己截取
(2) arguments object 是 array-like 物件, rest 是 array 物件, 所以 rest 不用轉型就可以使用 sort, map, forEach 等 functions.

rayway30419

rest 是 array 物件, 所以 rest 不用轉型就可以使用 sort, map, forEach 等 functions.
這點很棒

allen.hsieh :
至於 Spread Operator,可以想像成容器,在函式可以代表多個參數,在陣列可以代表多個元素,在解構時可以代表多個變數。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant