ecmascript-2017

What makes ES6 so special?

眉间皱痕 提交于 2019-12-13 07:46:51
问题 So I've only recently started to dive head first into web development. One thing I gathered very quickly was that ES5 = old, and ES6 = shiny and new. I figured ES6 was the latest and greatest ES had to offer. But I just found out that ES6 is 3 standards behind, and that some of the features I've been using and loving aren't even a part of it—they came in later specifications. So why does everything I read make it seem like there's just ES5 and ES6? 回答1: ES6 (later rebranded as ES2015 ) simply

ECMAScript 2017: Why does EscapeSequence include NonEscapeCharacter?

旧巷老猫 提交于 2019-12-12 18:20:37
问题 The below excerpts refer to ECMAScript 2017. 11.8.4 String Literals, Note 1 A string literal is zero or more Unicode code points enclosed in single or double quotes. Unicode code points may also be represented by an escape sequence. .... Any code points may appear in the form of an escape sequence. 11.8.4 String Literals, Syntax Nonterminal symbol EscapeSequence has the following lexical grammar production: EscapeSequence :: CharacterEscapeSequence 0 [lookahead ∉ DecimalDigit]

JS: Handle with find() property undefined

て烟熏妆下的殇ゞ 提交于 2019-12-12 17:14:31
问题 I have a method which returns a value from an element in the array. Not all the elements have the property I want to return. I would like to do this function with one line using the method find() . I've tried this way to solve it: getExecsFromTour(tourId){ return this.repInfo.find(el => el.id == tourId ).execs || []; } But the elements which don't contain the property execs return an error of undefined . To solve it, I had to store the result in a local variable: getExecsFromTour(tourId){ let

Difference in the 'lib' property in tsconfig.json between es6 and es2017?

白昼怎懂夜的黑 提交于 2019-12-12 08:29:37
问题 I've been researching what the possible values of the lib property mean in the compilerOptions found within the tsconfig.json file. I found on the Typescript GitHub page the relevant d.ts files corresponding to those values and apparently by using ES2017 the following ES features are included: /// <reference path="lib.es2016.d.ts" /> /// <reference path="lib.es2017.object.d.ts" /> /// <reference path="lib.es2017.sharedmemory.d.ts" /> /// <reference path="lib.es2017.string.d.ts" /> ///

Reuse object literals created via destructuring

做~自己de王妃 提交于 2019-12-11 06:07:21
问题 I am trying to reuse the object literals for both async calls. At the end my expect should check the success of the deleteBucket call. Problem is I can't do this, or it says I've got dup variables defined: it('can delete a bucket', async () => { const options = { branch: '11' } let { failure, success, payload } = await deployApi.createBucket(options) let { failure, success, payload} = await deployApi.deleteBucket(options.branch) expect(success).to.be.true }) Someone told me I could put a ()

In Angular, how to handle promise reject when using async/await

本小妞迷上赌 提交于 2019-12-11 06:07:16
问题 In Angular, if I use promise, the code would be let promise = this.$resource('www.example.com.au/request.json').get().$promise promise.then(data => { //promise solved }, () => { //promise rejected }) when it comes to async/await the code becomes async getData() { let data = await this.$resource('www.example.com.au/request.json').get().$promise this.localData = {...data} } but this is only for promise solved. if it is promise rejected, what should I do? thanks 回答1: If the promise is rejected,

avoid multiple returns looped in javascript - async / await to solve callback pyramid or callback hell,

大憨熊 提交于 2019-12-11 04:15:17
问题 I have this code, with a lot of blocks of returns, by example SignUp() connectors.js const connectors = { Auth: { signUp(args) { return new Promise((resolve, reject) => { // Validate the data if (!args.email) { return reject({ code: 'email.empty', message: 'Email is empty.' }); } else if (!isEmail(args.email)) { return reject({ code: 'email.invalid', message: 'You have to provide a valid email.' }); } if (!args.password) { return reject({ code: 'password.empty', message: 'You have to provide

javascript: async / await – propagation required the entire call chain up? [duplicate]

帅比萌擦擦* 提交于 2019-12-11 03:47:42
问题 This question already has answers here : Is it OK to use async/await almost everywhere? (3 answers) Closed last year . I am wrapping a function returning a promises into an async function on a small helper function... trash(filesArray, { glob: false }) .then(() => { resolve(true); }).catch((err) => { return err; }) …because I like to use it synchronous using the await on the next-higher level: async empty(liveMode, force) { … await helpers.trashSync(trashFiles); // then doing further stuff...

Async throwing SyntaxError: Unexpected token (

こ雲淡風輕ζ 提交于 2019-12-10 18:39:42
问题 I'm running a test using the headless Chrome package Puppeteer: const puppeteer = require('puppeteer') ;(async() => { const browser = await puppeteer.launch() const page = await browser.newPage() await page.goto('https://google.com', {waitUntil: 'networkidle'}) // Type our query into the search bar await page.type('puppeteer') await page.click('input[type="submit"]') // Wait for the results to show up await page.waitForSelector('h3 a') // Extract the results from the page const links = await

Does awaiting a non-Promise have any detectable effect?

会有一股神秘感。 提交于 2019-12-10 13:28:31
问题 One can await a non-Promise and that's good so. All these expressions are valid and cause no error: await 5 await 'A' await {} await null await undefined Is there any detectable effect of awaiting a non-Promise? Is there any difference in behavior one should be aware of to avoid a potential error? Any performance differences? Are the following two lines completely same or do they theoretically differ?: var x = 5 var x = await 5 How? Any example to demonstrate the difference? PS: According