ecmascript-next

Decorators on functions

纵饮孤独 提交于 2019-12-20 09:46:23
问题 I see that babel.js decorators (available in "stage 1") implement the spec at https://github.com/wycats/javascript-decorators. It appears that decorators are limited to (1) classes, (2) accessors, and (3) methods. In my case, I want to use decorators on plain old functions , as in @chainable function foo() { } where (just an example) function chainable(fn) { return function() { fn.apply(this, arguments); return this; }; } I don't see any logical reason why decorators should not be able to

Is it OK to use async/await almost everywhere?

故事扮演 提交于 2019-12-19 02:07:09
问题 I'm currently writing small NodeJS CLI tool for personal usage and I've decided to try ES7 async/await feature with Babel. It's a network tool so I obviously have asynchronous network requests. I wrote a simple wrapper for request package: export default function(options) { return new Promise(function(resolve, reject) { request({...options, followAllRedirects: true, headers: { "user-agent": "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0" } }, (error, response, body

Events vs Streams vs Observables vs Async Iterators

蓝咒 提交于 2019-12-18 09:54:24
问题 Currently, the only stable way to process a series of async results in JavaScript is using the event system. However, three alternatives are being developed: Streams: https://streams.spec.whatwg.org Observables: https://tc39.github.io/proposal-observable Async Iterators: https://tc39.github.io/proposal-async-iteration What are the differences and benefits of each over events and the others? Do any of these intend to replace events? 回答1: There are roughly two categories of APIs here: pull and

Error: Missing class properties transform

倖福魔咒の 提交于 2019-12-17 07:15:25
问题 Error: Missing class properties transform Test.js : export class Test extends Component { constructor (props) { super(props) } static contextTypes = { router: React.PropTypes.object.isRequired } .babelrc : { "presets": ["es2015", "react", "stage-0"], "plugins": ["transform-class-properties"] } package.json : "babel-core": "^6.5.1", "babel-eslint": "^4.1.8", "babel-loader": "^6.2.2", "babel-plugin-react-transform": "^2.0.0", "babel-plugin-transform-class-properties": "^6.5.2", "babel-preset

What does the at symbol (@) do in ES6 javascript? (ECMAScript 2015)

十年热恋 提交于 2019-12-17 04:01:11
问题 I'm looking at some ES6 code and I don't understand what the @ symbol does when it is placed in front of a variable. The closest thing I could find has something to do with private fields? Code I was looking at from the redux library: import React, { Component } from 'react'; import { bindActionCreators } from 'redux'; import { connect } from 'redux/react'; import Counter from '../components/Counter'; import * as CounterActions from '../actions/CounterActions'; @connect(state => ({ counter:

JavaScript double colon (bind operator)

穿精又带淫゛_ 提交于 2019-12-17 02:28:28
问题 As you know, there is a proposal for a shortcut for .bind() function, so you can write: ::this.handleStuff and it will work like that in es5: this.handleStuff.bind(this) My question is: will it be possible to pass arguments this way? I mean a way of writing this with the aforementioned shortcut: this.handleStuff.bind(this, 'stuff') It's a pretty common pattern in React, so it would be nice to shorten it a little. 回答1: No. The bind operator (spec proposal) comes in two flavours: Method

ES6 React: Will ES.Next's @autobind bind methods only once for each instance?

拜拜、爱过 提交于 2019-12-14 01:30:39
问题 There are a lot of questions/articles written on the numerous ways to handle binding in ES6 React, but most don't seem to address a problem outlined in the React docs ( emphasis mine): We recommend that you bind your event handlers in the constructor so they are only bound once for every instance : constructor(props) { super(props); this.state = {count: props.initialCount}; this.tick = this.tick.bind(this); } For context, they're advising against in-line binding of methods, such as: //using

Is async/await no place in functional programming JavaScript [closed]

故事扮演 提交于 2019-12-13 17:21:41
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 years ago . I am learning monad with JavaScript. Promise itself is monad, and is the right way to handle async side effects functionally. How about the es7 new player async/await, can we use it in functional programming of JavaScript? I feel like it falls well defined promise monad back

Will JSON Evolve to Have Native Support for Ecmascript Map Objects?

我的未来我决定 提交于 2019-12-13 09:34:30
问题 Are there any formal proposals, in progress, that address a backwards-compatible evolution to JSON's current treatment of Map objects? For example, let say you want to convert a Map to JSON and then write it to file: let map = new Map(); map.set(1, "A"); map.set(2, "B"); map.set(3, "C"); // Convert map to an "array of 2-element arrays": let arrayFromMap = [... map]; let json = JSON.stringify(arrayFromMap); writeJSONtoFile(json,"path/to/jsonFile.json"); So now we have a JSON file sitting on

What makes ES6 so special?

眉间皱痕 提交于 2019-12-13 07:46:51
问题 So I've only recently started to dive head first into web development. One thing I gathered very quickly was that ES5 = old, and ES6 = shiny and new. I figured ES6 was the latest and greatest ES had to offer. But I just found out that ES6 is 3 standards behind, and that some of the features I've been using and loving aren't even a part of it—they came in later specifications. So why does everything I read make it seem like there's just ES5 and ES6? 回答1: ES6 (later rebranded as ES2015 ) simply