ecmascript-next

ESLint unexpected character '@' for JS decorators

时光怂恿深爱的人放手 提交于 2019-12-05 02:57:46
I'm trying to use decorators in my JS project, however ESLint is throwing an error stating that the @ symbol is a unexpected character. My code: @observable items = []; My .eslintrc: { "parserOptions": { "ecmaVersion": 6, "ecmaFeatures": { "jsx": true }, "sourceType": "module" }, "env": { "browser": true, "node": true, "es6": false }, "ecmaFeatures": { "modules": true }, "rules": { "strict": [ 2, "global" ], "quotes": [ 2, "single" ], "indent": [ 2, 4 ], "eqeqeq": [ 2, "smart" ], "semi": [ 2, "always" ], "max-depth": [ 2, 4 ], "max-statements": [ 2, 15 ], "complexity": [ 2, 5 ] } } You

What is ESNext?

左心房为你撑大大i 提交于 2019-12-05 01:29:45
I've come across the term "ESNext", and wondering it is same as the EcmaScript. So, I have these questions here: What is ESNext, actually? Does it refer to any specific version of EcmaScript? What is ESNext, actually? It varies depending on who's using the term, usually "the next" version of ECMAScript (JavaScript). For instance, at this moment if someone said "ESNext" they might be talking about ES2019 plus BigInt, dynamic import, and other features that recently reached Stage 4 of the process , or they might even be talking about those plus some advanced Stage 3 proposals. Does it refer to

using the … spread syntax in javascript es6 named exports

橙三吉。 提交于 2019-12-04 16:03:18
问题 I am attempting to import everything from a library as a hash, modify it, and re-export the modified hash, without knowing all of the named exports in a library. For example: import * as reactBootstrap from 'react-bootstrap'; wrappedReactBootstrap = doFunnyThingsTo(reactBootstrap); export { ...wrappedReactBootstrap }; // or export wrappedReactBootstrap; My understanding of https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export is that the following is not allowed

JavaScript async/await for Promises inside Array.map() [duplicate]

依然范特西╮ 提交于 2019-12-04 15:05:41
This question already has an answer here: Using async/await with a forEach loop 15 answers Given the following code class SomeClass { async someFunc() { const urlParameters = [0, 1, 2]; const batchAjaxResult = await urlParameters.map((parameter) => { const result = await $.get(`someUrl/${parameter}`); return { parameter, result } }); console.log(batchAjaxResult); } } JavaScript will return an Array of resolved Promises instead of the actual Promises result. This is probably due to Array.map() not being implemented as a Promise. Is there a Promise-based version of Array.map ? This is question

While loops using Await Async.

强颜欢笑 提交于 2019-12-04 10:11:48
问题 This Javascript function seems to use the while loop in an asynchronous way. Is it the correct way to use while loops with asynchronous conditions? var Boo; var Foo = await getBar(i) while(Foo) { Boo = await getBar3(i) if (Boo) { // something } Foo = await getBar(i) i++ } What I think it does is this: var Boo; var Foo; getBar(i).then( (a) => { Foo = a; if(Foo) { getBar3(i).then( (a) => { Boo = a if(Boo) { //something i++; getBar(i).then( (a} => { Repeat itself...} } } } }) If that's totally

How do I get decorators working with babel & webpack?

喜你入骨 提交于 2019-12-04 07:36:41
I have the following setup: { "babel-core": "~5.8.25", "babel-eslint": "^4.1.3", "babel-loader": "~5.3.2", "babel-polyfill": "^6.2.0", "eslint": "^1.7.3", "eslint-config-airbnb": "^0.1.0", "eslint-loader": "~1.1.0", "eslint-plugin-angular": "~0.12.0", // ... } webpack: module: { preLoaders: [{ test: /\.js$/, exclude: /node_modules/, loader: 'eslint-loader'}], loaders: [ { test: /\.js$/, exclude: /node_modules/, loaders: ['ng-annotate', 'babel-loader?plugins[]=transform-decorators-legacy'], } ] } But I get the following error: TypeError: The plugin "transform-decorators-legacy" didn't export a

Dependency injection library - renaming injected values

隐身守侯 提交于 2019-12-04 06:15:46
I'd like to inject lodash by name, something like this: let val = function(lodash){ // lodash will be injected, simply by using require('lodash'); }; but say I want to rename the import, I want do something like this: let val = function({lodash:_}){ }; or let val = function(lodash as _){ }; is there a way to do this with either ES6/ES7/ES8 or TypeScript? Note that this DI framework does more work than just require('x')...it will try to inject other values first, if nothing else exists, then it will attempt to require the value. Note also that the requirements here are that when you call val

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

南笙酒味 提交于 2019-12-04 05:45:06
问题 I'm new to using ES6 classes with React, previously I've been binding my methods to the current object (show in first example), but does ES6 allow me to permanently bind a class function to a class instance with arrows? (Useful when passing as a callback function.) I get errors when I try to use them as you can with CoffeeScript: class SomeClass extends React.Component { // Instead of this constructor(){ this.handleInputChange = this.handleInputChange.bind(this) } // Can I somehow do this? Am

Clean way to keep original variable and destruction at the same time

房东的猫 提交于 2019-12-04 03:22:51
Is there a cleaner way to do this (with anything that is at least an ES draft and has a babel plugin, i.e., ES6, ES7, etc.): const { a, b } = result = doSomething(); Where I want to keep the overall result as one singular object, but also destructure it at the same time. It technically works, but result is implicitly declared (with an implicit var ), while I'd really like it to also be a const. I'm currently doing this: const result = doSomething(); const { a, b } = result; Which again works, but it's slightly on the verbose side, since I need to repeat this pattern dozens of times. I'd

Destructuring object and ignore one of the results

时间秒杀一切 提交于 2019-12-04 02:52:42
问题 I have: const section = cloneElement(this.props.children, { className: this.props.styles.section, ...this.props, }); Inside this.props , I have a styles property that I don't want to pass to the cloned element. How can I do? 回答1: 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, ..