Why await is not working for node request module?

You should only await on something that returns a Promise. I would definitely recommend reading up on Promises before you start working with async and await. You can probably get this example to work by creating your own wrapper function around request to make it return a promise, like so: function doRequest(url) { return new … Read more

What are “class fields” in JavaScript?

Simply put, the reason to use this is ease of understanding the code. Without class field declarations, you would do something like: class Person { constructor() { this.firstName = “Mike”; this.lastName = “Patel”; this.getName = () => { return this.firstName + ” ” + this.lastName; }; } } var p = new Person(); console.log(p.firstName); // … Read more

Unable to use Arrow functions inside React component class [duplicate]

It’s not the arrow function that’s causing a problem here. Class properties are not part of the ES6 specification. handleUpdateInput = (value) => { // … }; If you want to be able to transform this code, you’ll need to add the class properties babel plugin. Alternatively, this transform is provided as part of Babel’s … Read more

How to know if a function is async?

Theory Native async functions may be identifiable when being converted to strings: asyncFn[Symbol.toStringTag] === ‘AsyncFunction’ Or by AsyncFunction constructor: const AsyncFunction = (async () => {}).constructor; asyncFn instanceof AsyncFunction === true This won’t work with Babel/TypeScript output, because asyncFn is regular function in transpiled code, it is an instance of Function or GeneratorFunction, not AsyncFunction. … Read more

JavaScript array .reduce with async/await

The problem is that your accumulator values are promises – they’re return values of async functions. To get sequential evaluation (and all but the last iteration to be awaited at all), you need to use const data = await array.reduce(async (accumP, current, index) => { const accum = await accumP; … }, Promise.resolve(…)); That said, … Read more

JavaScript double colon (bind operator)

No. The bind operator (spec proposal) comes in two flavours: Method extraction ::obj.method ≡ obj.method.bind(obj) “virtual method” calls obj::function ≡ function.bind(obj) obj::function(…) ≡ function.call(obj, …) Neither of them feature partial application. For what you want, you should use an arrow function: (…args) => this.handleStuff(‘stuff’, …args) ≡ this.handleStuff.bind(this, ‘stuff’)

How to use arrow functions (public class fields) as class methods?

Your syntax is slightly off, just missing an equals sign after the property name. class SomeClass extends React.Component { handleInputChange = (val) => { console.log(‘selectionMade: ‘, val); } } This is an experimental feature. You will need to enable experimental features in Babel to get this to compile. Here is a demo with experimental enabled. … Read more