Skip to content

Instantly share code, notes, and snippets.

@ctbui
Created July 16, 2018 18:17
Show Gist options
  • Save ctbui/45f06a1a156e60f095d63da99e01f20d to your computer and use it in GitHub Desktop.
Save ctbui/45f06a1a156e60f095d63da99e01f20d to your computer and use it in GitHub Desktop.
// https://medium.freecodecamp.org/here-are-examples-of-everything-new-in-ecmascript-2016-2017-and-2018-d52fa3b5a70e
// EcmaScript2017
// 1. Object.values()
const car = {BMW: 1, Audi: 2, Tesla: 3};
console.log(Object.values(car)); // [1, 2, 3]
// ESMA2015
console.log(Object.keys(car)); // ["BMW", "Audi", "Tesla"]
// 2. Object.entries()
Object.entries(car).forEach(([key, value]) => console.log(`${key}=>${value}`))
// BMW=>1
// Audi=>2
// Tesla=>3
// 3. String padding
'5'.padStart(10) // ' 5'
'5'.padStart(10, '=*') //'=*=*=*=*=5'
'5'.padEnd(10) // '5 '
'5'.padEnd(10, '=*') //'5=*=*=*=*='
// 4. Object.getOwnPropertyDescriptors
var Car = {
name: 'BMW',
price: 1000000,
set discount(x) {
this.d = x;
},
get discount() {
return this.d;
},
};
console.log(Object.getOwnPropertyDescriptor(Car, 'discount'));
const ElectricCar = Object.assign({}, Car);
console.log(Object.getOwnPropertyDescriptor(ElectricCar, 'discount'));
const ElectricCar2 = Object.defineProperties({}, Object.getOwnPropertyDescriptors(Car));
console.log(Object.getOwnPropertyDescriptor(ElectricCar2, 'discount'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment