import and call a function with es6 [duplicate]
You’ll need two lines: import debugModule from ‘debug’; const debug = debugModule(‘http’); The import syntax is a declarative import syntax, it does not execute any functions.
You’ll need two lines: import debugModule from ‘debug’; const debug = debugModule(‘http’); The import syntax is a declarative import syntax, it does not execute any functions.
Add JSON.stringify when calling an asynchronous function that returns an object. Try modifying your getStaticProps function like this. export async function getStaticProps() { const profiles = await getAllBusinessProfiles(); const allProfiles = JSON.stringify(profiles) return { props: { allProfiles } }; } The JSON.stringify() method converts a JavaScript object or value to a JSON string, optionally replacing … Read more
It seems imports are not implemented in either Node 6 or Chrome 51 so Electron also does not support them, according to this post: https://discuss.atom.io/t/does-electron-support-es6/19366/18 And also the last electron doc doesn’t use imports, they use destructuring syntax: const { BrowserWindow } = require(‘electron’).remote // or const { remote } = require(‘electron’) const { BrowserWindow … Read more
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
Yes, blocks are going to replace IEFEs, as soon as block-scoped declarations (functions, let/const/class) become widely adopted. You need a scope, e.g. for a closure? Here you have a block, be it a loop body or just part of a statement list. However, there is still one application of IEFEs that blocks cannot replace: the … Read more
When you use the function body version of an arrow function (with {}), there is no implied return. You have to specify it. When you use the concise body (no {}), the result of the body expression is implicitly returned by the function. So you would write that either with an explicit return: const f … Read more
You say you tried importing the wildcard and spying on default? What was the issue with that approach? I just ran into this problem and doing this solved it for me: import * as widget from ‘./widget’; describe(‘widget spec’, () => { beforeEach(() => { spyOn(widget, ‘default’); }); });
In your example given, there is essentially no difference between the two .concat is significantly more efficient: http://jsperf.com/spread-into-array-vs-concat because … (spread) is merely syntax sugar on top of more fundamental underlying syntax that explicitly iterates over indexes to expand the array. Spread allows sugared syntax on top of more clunky direct array manipulation To expand … Read more
class Y extends X { constructor(name) { super(name); } set name(name) { super.name = name; this._name += “Y”; } } will override the name properly with an accessor for just the setter, with no getter. That means your y.name === “hiXY” will fail because y.name will return undefined because there is no getter for name. … Read more