ecmascript-6

switch statement and scopes in ES2015

£可爱£侵袭症+ 提交于 2021-02-08 23:44:52
问题 Consider this ES2015 module and the behavior when run in node v4.4.5. 'use strict' const outer = 1 switch ('foo') { case 'bar': const heyBar = 'HEY_BAR' break case 'baz': const heyBaz = 'HEY_BAZ' break default: const heyDefault = 'HEY_DEFAULT' } console.log( outer, // 1, makes sense, same top-level scope heyBar, // undefined. huh? I thought switch did NOT create a child scope heyBaz, // undefined. huh? I thought switch did NOT create a child scope heyDefault) // 'HEY_DEFAULT' makes sense This

switch statement and scopes in ES2015

☆樱花仙子☆ 提交于 2021-02-08 23:44:00
问题 Consider this ES2015 module and the behavior when run in node v4.4.5. 'use strict' const outer = 1 switch ('foo') { case 'bar': const heyBar = 'HEY_BAR' break case 'baz': const heyBaz = 'HEY_BAZ' break default: const heyDefault = 'HEY_DEFAULT' } console.log( outer, // 1, makes sense, same top-level scope heyBar, // undefined. huh? I thought switch did NOT create a child scope heyBaz, // undefined. huh? I thought switch did NOT create a child scope heyDefault) // 'HEY_DEFAULT' makes sense This

Is there an elegant way to tell eslint to ensure that we're not using any ES6 syntax / functions?

邮差的信 提交于 2021-02-08 15:09:55
问题 Is there an elegant way to tell ESLint to ensure that we're not using any ES6 / EMCAScript 2015 syntax / functions? I've found the following answer somewhat helpful but it seems that it doesn't take care of everything (e.g. I don't see how to catch the usage of Object.assign()): How to disable usage of certain ES2015 features with ESLint 2? 回答1: eslint-plugin-es5 is the package dedicated to your use case. For example the rule es5/no-es6-static-methods forbids the usage of Object.assign . 来源:

Is there an elegant way to tell eslint to ensure that we're not using any ES6 syntax / functions?

主宰稳场 提交于 2021-02-08 15:01:27
问题 Is there an elegant way to tell ESLint to ensure that we're not using any ES6 / EMCAScript 2015 syntax / functions? I've found the following answer somewhat helpful but it seems that it doesn't take care of everything (e.g. I don't see how to catch the usage of Object.assign()): How to disable usage of certain ES2015 features with ESLint 2? 回答1: eslint-plugin-es5 is the package dedicated to your use case. For example the rule es5/no-es6-static-methods forbids the usage of Object.assign . 来源:

Is there an elegant way to tell eslint to ensure that we're not using any ES6 syntax / functions?

这一生的挚爱 提交于 2021-02-08 15:01:06
问题 Is there an elegant way to tell ESLint to ensure that we're not using any ES6 / EMCAScript 2015 syntax / functions? I've found the following answer somewhat helpful but it seems that it doesn't take care of everything (e.g. I don't see how to catch the usage of Object.assign()): How to disable usage of certain ES2015 features with ESLint 2? 回答1: eslint-plugin-es5 is the package dedicated to your use case. For example the rule es5/no-es6-static-methods forbids the usage of Object.assign . 来源:

Understanding Maps vs Objects MDN documentation

三世轮回 提交于 2021-02-08 13:56:17
问题 There's a question here which is similar but is specific to "when keys are unknown at runtime". The MDN docs for Map state: Use maps over objects when keys are unknown until run time, and when all keys are the same type and all values are the same type. Use objects when there is logic that operates on individual elements. I understand the advice about using maps "when keys are unknown until run time". I'm confused by the line "when all keys are the same type and all values are the same type".

Passing parameters to a callback function using arrow function

烂漫一生 提交于 2021-02-08 12:37:13
问题 I know this is a duplicated question with ES5, but I am looking for the syntax with ES6 arrow function. My code below: fetchItems = (callback) => { //After ajax success callback(response); } const myParams = {name:"John"} this.fetchItems((res) => { console.log(res.data); }); For the above scenario, I want to pass some parameters( myParams ) along with the function call, how can I achieve that? 回答1: You can do that: const fetchItems = (callback, ...params) => { //Do whatever you want with the

Mapping checkboxes inside checkboxes ReactJS

♀尐吖头ヾ 提交于 2021-02-08 12:19:29
问题 I have a function which triggers children checkboxes once main checkbox is checked, and all these checkboxes are mapped from JSON. The main checkboxes (Highest level) and all of its children checkboxes (2nd level) under them are shown on click and its working great, what I am trying to display is the children of those children of the main checkboxes (3rd level) on clicking the 2nd level items. Basically to show all three orders under each other on check, and add the 3rd order to my current

Mapping checkboxes inside checkboxes ReactJS

假如想象 提交于 2021-02-08 12:18:06
问题 I have a function which triggers children checkboxes once main checkbox is checked, and all these checkboxes are mapped from JSON. The main checkboxes (Highest level) and all of its children checkboxes (2nd level) under them are shown on click and its working great, what I am trying to display is the children of those children of the main checkboxes (3rd level) on clicking the 2nd level items. Basically to show all three orders under each other on check, and add the 3rd order to my current

Destructuring an array of objects with es6

做~自己de王妃 提交于 2021-02-08 12:12:29
问题 I am trying to destructure an array of objects with three properties into three separate arrays for example maybe something like const {wlAddresses,wlTokens,wlTickets} = Object.map() or const [wlAddresses,wlTokens,wlTickets] = Object.map() Where Object.map() returns something like this [{ wlAddresses: '23', wlTokens: 1, wlTickets: 3 }, { wlAddresses: '24', wlTokens: 1, wlTickets: 2 }, { wlAddresses: '25', wlTokens: 1, wlTickets: 3 }] I tried with that method and it only returns the first