Created
March 22, 2016 21:46
-
-
Save cryptoquick/a7d8f93e81317cb4a82b to your computer and use it in GitHub Desktop.
ESNext Examples
This file contains hidden or 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 c = 'c' | |
const target = { | |
a: true, b: 1 | |
}; | |
const anotherObj = { | |
c | |
}; | |
console.log(Object.assign(target, anotherObj)); | |
const betterObj = { | |
...target, | |
c | |
} | |
console.log(betterObj) | |
const arr1 = [1, 2, 3] | |
const arr2 = [4, 5, 6] | |
const betterArr = [ | |
...arr1, ...arr2 | |
] | |
console.log(betterArr) | |
console.log(`${c} u later`) | |
// ES5 | |
for (var i = 0; i < arr2.length; i++) { | |
// console.log(i) | |
// console.log(arr2[i]) | |
} | |
for (var key in betterObj) { | |
var propertyName = key | |
var value = betterObj[key] | |
} | |
// ES6 | |
for (let val of betterArr) { | |
console.log(val) | |
} | |
// async & await | |
// Prior to ES7 | |
createNewStripeToken().then(function (stripeResult) { | |
paymentCtrl().subscribe(req, res).then(function (paymentResult)) { | |
console.log(stripeResult, paymentResult) | |
}, function (err) { | |
console.error(err) | |
}) | |
}, function (err) { | |
console.error(err) | |
}) | |
// ES7 | |
async function () { | |
try { | |
const stripeResult = await createNewStripeToken() | |
const paymentResult = await paymentCtrl().subscribe(req, res) | |
console.log(stripeResult, paymentResult) | |
} | |
catch (err) { | |
console.error(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment