ecmascript-next

What are ES7 Async functions? [closed]

邮差的信 提交于 2019-12-12 17:14:15
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . I have been using Babel for a while now, and I am loving it. However, on the home page, where it lists the supported features, it says Async functions . I have done a lot of Googling, and all I can seem to understand is that it's an ES7 feature. Please what are ES7 Async functions? 回答1: Async Await work with ES6

React - ES6 - Unexpected token [duplicate]

百般思念 提交于 2019-12-12 05:26:22
问题 This question already has answers here : Unable to use Arrow functions inside react component class [duplicate] (2 answers) Closed 2 years ago . I'm getting this error ERROR in ./src/components/Header/index.js Module build failed: SyntaxError: C:/Users/Gil/Documents/Projects/ecommerce/src/components/Header/index.js: Unexpected token (16:7) 14 | } 15 | > 16 | test = () => { | ^ 17 | console.log('pass!'); 18 | }; 19 | i think its something with ES6, but i dont know, anyway here's my config

ES6 Class Property Definition

陌路散爱 提交于 2019-12-11 23:27:52
问题 So I've read around stackoverflow. In ES6 this is invalid: class MyClass { myProperty = ""; constructor() { this.myProperty = "Hey"; } } But it is valid in ES7. However, is this valid: class MyClass { setViewModel(viewModel) { this.internalViewModel = viewModel; } get viewModel() { return this.internalViewModel } } Here I haven't defined internalViewModel until I've actually set it. I expect that if you haven't called myClass.setViewModel(something) before you call myClass.viewModel , you

Babel - decorator of decorated class properties is called before instantiating class

十年热恋 提交于 2019-12-11 17:32:41
问题 Excuse me for creating a new question, I was not able to find a question addressing this matter. I am having difficulties testing my dependency injection using mocha and experimental es6+ decorators transpiled using babel. The class property decorator is being called before it should've been. injection.test.js (mocha test, using --require babel-register ) import * as DependencyInjection from '../build/decorators/DependencyInjection'; @DependencyInjection.Injectable(service => service.injected

Try/Catch Functions: False versus Falsy

本秂侑毒 提交于 2019-12-11 08:16:38
问题 This is a petty question that will make you cringe, but I'm still curious. Is it slightly more efficient (for if/then logic) to evaluate an explicit false over falsy values such a null or undefined ? When I try/catch inside of a function, with the intent of recovering from an unimportant (yet) application-halting error, I typically returned undefined when the try portion cannot not succeed. However, below I'm returning false instead of undefined : var parseJSON = function(jsonString) { try {

Convert an Observable to an async generator

こ雲淡風輕ζ 提交于 2019-12-11 01:48:51
问题 I'm trying to use rxjs in conjunction with babeljs to create an async generator function that yields when next is called, throws when error is called, and finishes when complete is called. The problem I have with this is that I can't yield from a callback. I can await a Promise to handle the return/throw requirement. async function *getData( observable ) { await new Promise( ( resolve, reject ) => { observable.subscribe( { next( data ) { yield data; // can't yield here }, error( err ) {

Get List of Supported Currencies

孤街浪徒 提交于 2019-12-10 15:54:24
问题 Other than just guessing (like I've done below), is there a more direct and efficient way of reflectively retrieving a list of all currencies supported by your JavaScript environment? function getSupportedCurrencies() { function $(amount, currency) { let locale = 'en-US'; let options = { style: 'currency', currency: currency, currencyDisplay: "name" }; return Intl.NumberFormat(locale, options).format(amount); } const getAllPossibleThreeLetterWords = () => { const chars =

Extending/decorating Angular 2 components and directives

不羁的心 提交于 2019-12-10 10:39:36
问题 I have some use cases for inheritance and decoration (as in Decorator pattern) of components and directives in Angular 2. The example is component with basic template that doesn't suit the case, to the point when it easier to define a new template instead of modifying the DOM of existing one programmatically. The rest of component metadata should be inherited. Basically it is export const BASE_SOME_COMPONENT_METADATA = { ... }; @Component(BASE_SOME_COMPONENT_METADATA); export class

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

别来无恙 提交于 2019-12-09 16:11:59
问题 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,

Is the constructor still needed in React with autobinding and property initializers

放肆的年华 提交于 2019-12-09 05:24:56
问题 I am refactoring an es6 class based React component that uses the normal constructor, and then binds methods, and defines state/attributes within that constructor. Something like this: class MySpecialComponent extends React.Component { constructor(props) { super(props) this.state = { thing: true } this.myMethod = this.myMethod.bind(this) this.myAttribute = { amazing: false } } myMethod(e) { this.setState({ thing: e.target.value }) } } I want to refactor this so that I am autobinding the