Created
January 31, 2018 03:20
-
-
Save alexmasyukov/99cdff6f313b766bfde22a65f9fc8af6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const [,, first, second] = array; | |
const [one, ...rest] = array; // разделит массив на остатки | |
const { name, age } = me; | |
const { name: firstName, age } = me; | |
const me = { | |
age: 26, | |
gender: "male", | |
city: "nsk" | |
}; | |
const { name = 'noname', age } = me; | |
// ArrowFunctions (Сохраняют контекст) | |
const a3 = a.map(el => el * 2); | |
const increment = n => n + 1; | |
// Functions arguments | |
const sayHelloNew = (name = 'noname') => `Hello new ${name}`; | |
// | |
const sayHelloNew = (name = 'noname') => ({ | |
name: `Hello new ${name}` | |
}) | |
// вернет объект, потому как () вместо return | |
const sayHello = (...people) => console.log(`Hello ${people.join(', ')}`); | |
sayHello('Alex', 'Test', 'Test2'); | |
// people - это РЕАЛЬНЫЙ массив | |
const sayHello = (firstPerson, ...others) => console.log(`Hello ${firstPerson} and ${others.join(', ')}`); | |
// Деструктуризация внутри аргументов функции | |
let Person = ({name = 'noname', age = 0, city = 'Nowhere'}) => { | |
console.log( `Hello from ${city}! my name is ${name}, I am ${age} years old.`) | |
} | |
let me = { | |
name: "alex", | |
city: "nsk" | |
} | |
Person(me); | |
// Objects | |
const name = "alex"; | |
const city = "nsk"; | |
const me = { | |
name, | |
city | |
} | |
// Назвать свойство из переменной | |
let propName = 'name'; | |
let user = { | |
[propName]: 'alex' | |
} | |
const obj = { | |
sayHello() { | |
return `Hello ${this.name}` | |
}, | |
name: "alex" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment