daily pastebin goal
58%
SHARE
TWEET

Untitled

a guest May 16th, 2018 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Rest 剩下的, Spread 展開 , Destructuring 將陣列或物件中的資料取出成獨立變數
  2.  
  3.  
  4. // Array Example
  5. // let a, b
  6. // [a, b, ...c] = [1, 2, 3, 4, 5]
  7. // c
  8.  
  9. // Obj Example
  10. // ({a, b, ...c} = {a: 1, b: 2, c: 3, d: 4, e: 5})
  11. // a
  12. // b
  13. // c
  14.  
  15. // example
  16. // const person = {
  17. //   name: 'danny',
  18. //   age: '30',
  19. //   city: 'KHH',
  20. //   gender: 'male'
  21. // }
  22.  
  23. // ES5
  24. // const name = person.name,
  25. //       age = person.age,
  26. //       city= person.city
  27.  
  28. // ES6
  29. // const { name, age, city, gender } = person
  30.  
  31. // name
  32. // age
  33. // city
  34.  
  35. // Function example
  36.  
  37. const person = {
  38.   name: 'danny',
  39.   age: '30',
  40.   city: 'KHH',
  41.   gender: 'male'
  42. }
  43.  
  44. // const sayHi = (obj) => {
  45. //   console.log('Hi ' + obj.name + ' I am from ' + obj.city)
  46. // }
  47.  
  48. const sayHi = ({name, city, ...other}) => {
  49.   // console.log('Hi ' + name + ' I am from ' + city)
  50.   console.log(other)
  51. }
  52.  
  53. sayHi(person)
RAW Paste Data
Top