Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Rest 剩下的, Spread 展開 , Destructuring 將陣列或物件中的資料取出成獨立變數
- // Array Example
- // let a, b
- // [a, b, ...c] = [1, 2, 3, 4, 5]
- // c
- // Obj Example
- // ({a, b, ...c} = {a: 1, b: 2, c: 3, d: 4, e: 5})
- // a
- // b
- // c
- // example
- // const person = {
- // name: 'danny',
- // age: '30',
- // city: 'KHH',
- // gender: 'male'
- // }
- // ES5
- // const name = person.name,
- // age = person.age,
- // city= person.city
- // ES6
- // const { name, age, city, gender } = person
- // name
- // age
- // city
- // Function example
- const person = {
- name: 'danny',
- age: '30',
- city: 'KHH',
- gender: 'male'
- }
- // const sayHi = (obj) => {
- // console.log('Hi ' + obj.name + ' I am from ' + obj.city)
- // }
- const sayHi = ({name, city, ...other}) => {
- // console.log('Hi ' + name + ' I am from ' + city)
- console.log(other)
- }
- sayHi(person)
Add Comment
Please, Sign In to add comment