ecmascript-7

React passing parameter with arrow function in child component

心已入冬 提交于 2020-01-12 07:31:09
问题 I have these parent and child component, I want to pass click function to select an item in child component. Yet it seems the function in child component become automatically called instead of waiting until the user click the element. To make it clearer here is my parent and child components export class ParentView extends Component { state = { selectedItem: {} } handleClick = (item) => { alert('you click me'); this.setState({selectedItem: item}); } render() { let item = { name: 'Item-1' };

What is the relation between ES6, ES7 (and bigger), ES2015, stage-0, stage-1 (and bigger)?

匆匆过客 提交于 2020-01-12 05:29:08
问题 I am lately confused between the following terms in articles about "new-ish" JavaScript: ES6 ES7 (and sometimes, though rarely, ES8 and bigger) ES2015 (and sometimes ES2016 and bigger) stage-0 (and stage-1 and bigger) It seems some of those are subset, feature-wise, of the others, but I am not quite clear on which are subsets of which. 回答1: Fair enough, it is a bit confusing. :-) The four-digit numbers are years, the others are specification editions. ES2015 is ES6. It's short for ECMAScript

Add a return type of string when a function is accessed like a variable

荒凉一梦 提交于 2019-12-31 05:19:35
问题 I am not sure if this is possible (in fact I'm struggling to work out what to google for) but here it goes: I have a function const test = () => { some logic.. return bla } now when I use 'test()' I want the function executed. But when I use 'test' I want a custom string to be returned. Is it possible to achieve this via Object proxies somehow? 回答1: Is it possible to achieve this via Object proxies somehow? No, this is not possible. You cannot make a callable proxy as a primitive string. If

Why is Babel needed in an Electron project

ぐ巨炮叔叔 提交于 2019-12-23 20:39:10
问题 I'm quite confused about all the Javascript ecosystem. I'm trying Electron that seems a promising way in creating cross platform apps, leveraging the power of node and Chrome. I create a small app and used some "modern" ( this make a C# programmer laughing ) javascript concepts as lambdas, and it worked out of the box ( I supposed it was natural, since I've the latest version of node ). Then I'm trying to move next, and I see a lot of boilerplating in the examples using for example Babel. Why

SyntaxError: Unexpected token static

给你一囗甜甜゛ 提交于 2019-12-23 09:26:40
问题 I'm currently trying to evaluate different testing frameworks that work with React, and it turns out that Jest is on my list. However, I'm trying to use static properties outlined here: https://github.com/jeffmo/es-class-fields-and-static-properties. So, I took the tutorial that is given on the Jest homepage, and added a static propTypes property, my code looks like this: import React from 'react'; class CheckboxWithLabel extends React.Component { static defaultProps = {} constructor(props) {

Module Build Failed - Webpack, React, Babel

我只是一个虾纸丫 提交于 2019-12-23 07:46:36
问题 I was following a video tutorial from plural sight. Course name is "Building a Real-time App with React, Flux, Webpack, and Firebase". Please see below code and attached screen shot of the issue i am having. Webpack is failing when ever i try to re build the files. Can someone please advise of what that issue could be. I'm currently using all the latest libraries. /*webpack.config.js*/ module.exports = { entry: { main: [ './src/main.js' ] }, output: { filename: './public/[name].js' }, module:

How jasmine clock works?

天涯浪子 提交于 2019-12-23 07:09:00
问题 I don't want to read code for hours to find the relevant part, but I am curious how jasmine implements its clock. The interesting thing with it is that it can test async code with sync testing code. AFAIK, with the current node.js, which supports ES5, this is not possible (async functions are defined in ES7). Does it parse the js code with something like estraverse and build an async test from the sync one? Just an example of what I am talking about: it("can test async code with sync testing

Is ES7 only composed of two features?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-22 12:37:31
问题 According to this blog: https://webapplog.com/es7-es8/ ES7 features are: Array.prototype.includes Exponentiation Operator Is this right? If it is, why it took a year to commit only two minor changes to the standard ( Array.prototype.includes is just an alias to indexOf !== -1 )? 回答1: Yes , those were the new features ready at the time. Of course, there also have been lots of editorial changes that fixed minor spec issues. Notice that instead of ES7 (ECMAScript 7. Edition) one should rather

Error using ES7 async/await with node, webpack and babel-loader

会有一股神秘感。 提交于 2019-12-22 06:37:03
问题 I'm trying to use javascript ES7 syntax on the server using node.js with webpack and babel-loader (es2015 + stage-0 presets). I've gotten it to work with babel-node but when I run webpack I get the following error at the async keyword (9:22 is after the async keyword): ERROR in ./src/server.js Module parse failed: C:\dev\node-async-sample\src\server.js Unexpected token (9:22) You may need an appropriate loader to handle this file type. SyntaxError: Unexpected token (9:22) I've put the code on

Is there support for static typing in ECMAScript 6 or 7?

雨燕双飞 提交于 2019-12-21 03:12:50
问题 Is there any support for static typing in ECMAScript 6? How about ECMAScript 7? 回答1: No. But on the ECMA-Script Wikipage there is a paragraph about changes in ECMA-Script 7: The Seventh Edition is in a very early stage of development, but is intended to continue the themes of language reform, code isolation, control of effects and library/tool enabling from ES6. New features proposed include promises/concurrency, number and math enhancements, guards and trademarks (an alternative to static