ecmascript-6

React-native map/loop multidimensional array based on index of json?

懵懂的女人 提交于 2021-01-29 08:53:00
问题 I'm new to React-native and cannot figure out how to map this JSON: { "Category Title": { "data": [ { "id": 34, "name": "Blanditiis", "price": "10.30" }, { "id": 25, "name": "Dolor omnis", "price": "10.37" } ] }, "Second category": { "data": [ { "id": 30, "name": "Cupiditate maiores consectetur ut quos", "price": "9.79" }, { "id": 45, "name": "In facere sint quos", "price": "9.04" }, { "id": 7, "name": "Necessitatibus", "price": "14.25", } ] }, "Third category": { "data": [ { "id": 39, "name"

javascript: object destructuring

时光总嘲笑我的痴心妄想 提交于 2021-01-29 07:58:45
问题 I have a this object: { "userAuth": { "id": 1, "uuid": "e30fa23a-bfe4-495e-b6ac-79d49cb9a5a5", "login": 12, "password": "", "role": "WORKER_ROLE", "user": { "id": 2, "uuid": "f0ca9c33-a5b7-48c1-9956-1d4d372475ec", "firstName": "Adrian", "lastName": "Pietrzak", "email": "test111@test.com", "phone": null, "avatar": null, "street": "string", "city": "string", "state": "string", "zip": "string", "createdAt": "2019-10-12", "lastLogin": "2019-11-29T20:03:17.000Z", "lastLogout": null } }, "iat":

ES6, Must call super before accessing 'this' and defining constant in derived class

一曲冷凌霜 提交于 2021-01-29 07:53:16
问题 If I want to define a constant in base class, then override it in sub-classes, how should I do? The catch is that, for my specific case, this constant is a new Map() , and the result will be consulted with during constructor: class Cmd0 { constructor(name, arg1, arg2 = null) { this.name = name; this.arg1 = arg1; this.arg2 = arg2; } . . . } class Cmd extends Cmd0 { constructor(name, arg1, arg2 = null) { myMap = Somehow.getMyMap() // defined in sub-classes if (!myMap.has(name)) { super(null,

Only allowing one instance of a class member in javascript

人走茶凉 提交于 2021-01-29 07:38:37
问题 I am creating a helper class in front of the google map API - just for the sake of learning. I'd like to keep only one instance of the google.maps.Map object around in my class, even if someone decides to instantiate another instance of the class. I'm coming from a .NET background, and the concept is simple there - however I'm still getting acclimated to javascript (and ES6), so any pointers are much appreciated. Here's a snippet sort of explaining (through comments) what I'm going for. class

How to import jquery using ES6 syntax?

佐手、 提交于 2021-01-29 07:10:02
问题 I'm writing a new app using (JavaScript) ES6 syntax through babel transpiler and the preset-es2015 plugins, as well as semantic-ui for the style. index.js import * as stylesheet from '../assets/styles/app.scss'; import * as jquery2 from '../dist/scripts/jquery.min'; import * as jquery3 from '../node_modules/jquery/dist/jquery.min'; console.log($('my-app')); index.html <!DOCTYPE html> <html lang="fr"> <head> <body> <script src="dist/app.js"></script> </body> </html> Project structure . ├── app

Destructuring in a return statement [duplicate]

我与影子孤独终老i 提交于 2021-01-29 06:14:53
问题 This question already has answers here : One-liner to take some properties from object in ES 6 (11 answers) Closed 2 years ago . I have multiple cases throughout my app that look something like this: getVariables() { const { allowCustomValues, budgets, budgetsToAdd, budgetsToRemove, isGlobal, isRequired, name, tagTypeId, valuesToAdd, valuesToDelete, } = this.props; return { allowCustomValues, budgets, budgetsToAdd, budgetsToRemove, isGlobal, isRequired, name, tagTypeId, valuesToAdd,

ESLint rule for camelCased argument names

痴心易碎 提交于 2021-01-29 03:05:17
问题 I want to use camelCase function argument names: myFunc(goodArg, BadArg) { ... } I found ESLint's camelcase rule. Unfortunately it does not apply to argument names, just variables and properties. Is there a way to automatically just function argument names? I don't mind using another linter if it helps. 来源: https://stackoverflow.com/questions/36777168/eslint-rule-for-camelcased-argument-names

Why is using let resulting in undefined in a block of code?

坚强是说给别人听的谎言 提交于 2021-01-29 01:36:55
问题 When running code in a code block it results in 'undefined' then using the 'this' to reference a local variable in a block of code. The strange thing is when removing the 'this' keyword in the same block, it prints fine. let productId = 12; if (true) { let productId = 10 console.log(this.productId) // results in 'undefined' console.log(this) //results in '{}' console.log(productId) // results in '10' } Was under the impression that the 'this.productId' would refer directly to the productId in

Typescript extension method compiling but not working at run time

天涯浪子 提交于 2021-01-28 21:52:52
问题 I have extended the String prototype in Typescript with a simple method: StringExtensions.ts String.prototype.toCleanedTitleCase = function ():string { let titleCase = this.replace(/\w\S*/g, function (txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase() }) return titleCase.replace(new RegExp(" ", 'g'), "").replace(new RegExp("-", 'g'), "") } Then added an interface in a definition file: StringExtensions.d.ts interface String { toCleanedTitleCase():String; } Then calling it:

Sharing content between adjacent components, HOC?

瘦欲@ 提交于 2021-01-28 19:43:49
问题 I have a container component which renders two components inside it. Depending on some props in the container, the top component can change, but the lower component will always remain the same. I want to render some additional content (DOM elements/other react components) inside the lower component, but the additional content is created inside the top component. I'm struggling to figure out what I need to refactor here to make this work. I initially tried passing the created content up to the