ES6 code styles best practices

Recently I've started to learn ReactJS and consequently - ES6. I'm quite familiar with ES5, but some things are not that clear for me. Example 1: Methods syntax What is the difference between the following two methods? export class InvoiceForm ext...
more »

2017-12-03 22:12 (2) Answers

How to extend the Generator class?

I tried to filter a generator and had the expectation that this kind of general functionality must be defined anywhere in JavaScript, because it is defined for Arrays, but I can not find it. So I tried to define it. But I can not extend the built-in ...
more »

2017-11-28 15:11 (2) Answers

Mock Es6 classes using Jest

I'm trying to mock an ES6 class with a constructor that receives parameters, and then mock different class functions on the class to continue with testing, using Jest. Problem is I can't find any documents on how to approach this problem. I've alre...
more »

2017-11-21 11:11 (1) Answers

How to destructure keys out of an array (ES6)

We just made this code based on a hunch, and it worked. I'm pretty sure it's acceptable. I just want to make sure: const state = { inProgress: true } const actions = 'COMPLETE_RICE' const change = { inProgress: false, rice: 'cooked' } // Is...
more »

2017-11-21 09:11 (2) Answers

Spreading undefined in array vs object

Why does spreading undefined in an object return an empty object? {...undefined} // equals {}: console.log({...undefined}) And Why does spreading undefined in an array give you an error? [...undefined] // type error: console.log([......
more »

2017-11-07 11:11 (1) Answers

Merge two arrays with alternating Values

i would like to merge 2 arrays with a different length: let array2 = ["a", "b", "c", "d"]; let array2 = [1, 2]; let outcome = ["a",1 ,"b", 2, "c", "d"] Whats the best way to do that? Edit: The outcome I would expect is ["a", 1 ,"b", 2, "c", "d...
more »

2017-11-01 19:11 (3) Answers

build object and then export it , in js

I used to have an resolvers.js with an object: export const resolvers = { value1: 'value'; value2: 'value'; } and then: import { resolvers } from './graphqlresolvers'; now I need to build my object with variable properties let resolvers...
more »

2017-10-29 12:10 (2) Answers

Equivalent of set in ES6 to ES5

I have a set in which I am iterating over in ES6. I am trying to convert it to its equivalent in ES5. My build is getting failed because of ES6. That's why I am converting it to ES5. Here's my code in ES6 service.getDevices = function (date) { ...
more »

2017-10-24 19:10 (3) Answers

Get URL of current module script

I haven't found any mentions in the HTML spec nor anywhere in the web that says this is possible, still I ask just in case. Is it possible to get the URL of a module to for example fetch files relative to that URL? Let's say my index.html has a <...
more »

2017-10-11 17:10 (0) Answers

JavaScript invoking a function in different ways

What is difference / similarities between calling a function like the following ? What is the purpose of having these two ways? What are their pros and cons? Can someone explain how this call works -> sum(2)(3); ? And mention other conventional equ...
more »

2017-10-10 02:10 (3) Answers

ES6 promise execution order for returned values

Trying to understand the order of execution of ES6 promises, I noticed the order of execution of chained handlers is affected by whether the previous handler returned a value or a promise. Example let a = Promise.resolve(); a.then(v => Pr...
more »

2017-09-25 16:09 (2) Answers

Handling external function imports

This might be a rather general question on how to handle imports of external functions and exporting functions. So I have a component like this: import React, {Component} from "react"; import {handleChange} from "./path"; //imports from different...
more »

2017-09-25 15:09 (2) Answers

Fetch() 2 JSONs then() pass to function

I'm trying to plot a graph. The graph function, for obvious reasons, is executed last. The data sources are from different websites. One's rather fast (sourcex) and one's hosted in the middle of nowhere (or so it seems) (sourcey). So datax is from ...
more »

2017-09-07 07:09 (1) Answers