using the … spread syntax in javascript es6 named exports

Object rest spread is stage 3 proposal and not a part of any spec (will probably be included in ES2018). More importantly, export has syntax that mimics existing JS syntax but doesn’t interpret { … } as an expression. export syntax was strictly defined because ES2015 modules are supposed to be statically analyzed. This is … Read more

Can async/await be used in constructors? [duplicate]

To expand upon what Patrick Roberts said, you cannot do what you are asking, but you can do something like this instead: class MyClass { constructor() { //static initialization } async initialize() { await WhatEverYouWant(); } static async create() { const o = new MyClass(); await o.initialize(); return o; } } Then in your code … Read more

Node.js assert.throws with async functions (Promises)

node 10 and newer Since Node.js v10.0, there is assert.rejects which does just that. Older versions of node async functions never throw – they return promises that might be rejected. You cannot use assert.throws with them. You need to write your own asynchronous assertion: async function assertThrowsAsynchronously(test, error) { try { await test(); } catch(e) … Read more

Is it OK to put propTypes and defaultProps as static props inside React class?

In fact, it’s exactly the same in terms of performance. React.JS is a relatively new technology, so it’s not clear yet what are considered good practices or don’t. If you want to trust someone, check this AirBNB’s styleguide: https://github.com/airbnb/javascript/tree/master/react#ordering import React, { PropTypes } from ‘react’; const propTypes = { id: PropTypes.number.isRequired, url: PropTypes.string.isRequired, text: … Read more

Succinct/concise syntax for ‘optional’ object keys in ES6/ES7?

You can use object spread to have an optional property: let flag1 = true; let flag2 = false; // extra cases added by Abdull let optionalKey8 = 8; let optionalKey9 = undefined; let optionalKey10 = false; let optionalKey11 = null; let optionalKey12 = “twelve”; const obj = { requiredKey1: 1, requiredKey2: 2, …(flag1 && { … Read more

Destructuring object and ignore one of the results

You can use the object rest/spread syntax: // We destructure our “this.props” creating a ‘styles’ variable and // using the object rest syntax we put the rest of the properties available // from “this.props” into a variable called ‘otherProps’ const { styles, …otherProps } = this.props; const section = cloneElement(this.props.children, { className: styles.section, // We … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)