Immediate function using JavaScript ES6 arrow functions
From the Arrow functions examples, (() => “foobar”)() // returns “foobar” So, the function invocation operator should be outside. (() => { //… })(); Sample: http://www.es6fiddle.net/hsb8s1sj/
From the Arrow functions examples, (() => “foobar”)() // returns “foobar” So, the function invocation operator should be outside. (() => { //… })(); Sample: http://www.es6fiddle.net/hsb8s1sj/
I think maybe a better idea is to use an index file for your images folder. Supposing you have this structure: And you need to import all of your images to your HomePage component. You can easily create an index.js file on your images folder, exporting all the images using require, like this: export const … Read more
You can export object itself: export default { googleClientID:’xxxx’ }; The difference is that in your case you will get brand new object every time you call exported function. In this case you will get the same object every time. Depends on what you need.
It’s called destructuring assignment and it’s part of the ES2015 standard. The destructuring assignment syntax is a JavaScript expression that makes it possible to extract data from arrays or objects using a syntax that mirrors the construction of array and object literals. Source: Destructuring assignment reference on MDN Object destructuring var o = {p: 42, … Read more
I think you’re looking for the with statement, it does exactly what you are asking for: const vegetableColors = {corn: ‘yellow’, peas: ‘green’}; with (vegetableColors) { console.log(corn);// yellow console.log(peas);// green } However, it is deprecated (in strict mode, which includes ES6 modules), for good reason. destructure all properties into the current scope You cannot in … Read more
No, ES6 does not introduce any new number formatting functions, you will have to live with the existing .toExponential(fractionDigits), .toFixed(fractionDigits), .toPrecision(precision), .toString([radix]) and toLocaleString(…) (which has been updated to optionally support the ECMA-402 Standard, though). Template strings have nothing to do with number formatting, they just desugar to a function call (if tagged) or string … Read more
const can be normally used when you don’t want your program to assign anything to the variable “use strict”; const a = 1; a = 2; will produce TypeError: Assignment to constant variable.. to use the variable without explicitly initializing. “use strict”; const a; will produce SyntaxError: Unexpected token ; Simply put, I would say, … Read more
Immediately instantiated anonymous class — is it a bad idea? Yes, a very bad one. Just as bad as new function() { … } was in ES5. This writing style leads to the creation of a new constructor function and prototype object every time the expression is evaluated. If you create multiple objects with this … Read more
You cannot import all variables by wildcard for the first variant because it causes clashing variables if you have it with the same name in different files. //a.js export const MY_VAR = 1; //b.js export const MY_VAR = 2; //index.js import * from ‘./a.js’; import * from ‘./b.js’; console.log(MY_VAR); // which value should be there? … Read more
Edit: Add more examples. Your class definition is (almost) correct.The error was in instantiation var Reply = new Reply();. This tries to redefine variable assigned to class name. Also generator function is expected to yield something. I elaborated a little OP code to show working example. class Reply { //added for test purpose constructor(…args) { … Read more