arrow-functions Questions

5

Solved

How do you write a PHP arrow function with multiple line expressions? JavaScript one-liner example: const dob = (age) => 2021 - age; PHP one-liner equivalent: $dob = fn($age) => 2021 - $age;...
Theresatherese asked 26/1, 2021 at 15:6

11

Solved

Is there an elegant way to tell Harmony's slim arrow functions apart from regular functions and built-in functions? The Harmony wiki states that: Arrow functions are like built-in functions in ...

4

Solved

After complaining about the tumultuous task of writing the keyword function over and over, I asked someone about an easier way. The person said that PHP is going to have arrow function syntax simil...
Badger asked 5/2, 2018 at 7:9

10

Solved

I have two function in my react-app components componentDidMount() { if(Object.keys(this.props.praticiens).length>0) Object.keys(this.props.praticiens).map((praticien) => { if(this.props.p...
Sucking asked 30/6, 2020 at 8:37

5

Given class BaseClass{ count:number=0; public someMethod=():void =>{ this.count++; } } class ChildClass extends BaseClass{ public someMethod=():void=>{ super.someMethod(); //Do mo...
Juicy asked 22/4, 2014 at 12:3

4

Solved

I customerized the arrow shape and color of swiper js by adding svg, but it did not have any functionality. And I ended up having two sets of arrows on each side, one is my own arrow button which d...
Beloved asked 7/9, 2022 at 21:53

4

Solved

I'm just looking for a reason as to why this is invalid: () => throw 42; I know I can get around it via: () => {throw 42};
Eyeleteer asked 20/8, 2015 at 4:56

5

when defining a c++ lambda https://en.cppreference.com/w/cpp/language/lambda there is the capture block that captures the values of variables in the enclosing scope (at least if the variable is cap...
Cowles asked 12/5, 2020 at 21:28

6

Solved

When returning an object from an arrow function, it seems that it is necessary to use an extra set of {} and a return keyword because of an ambiguity in the grammar. That means I can’t write p =&g...
Limnetic asked 27/2, 2015 at 17:2

3

Solved

I got to know about arrow functions in PHP 7.4. I tried using them like <?php $num = 1; $arrowfunction = () => { return $num + 1; } echo $arrowfunction(); Because I saw the => operator...
Jessiajessica asked 18/6, 2019 at 21:14

8

I have been reading a bunch of React code and I see stuff like this that I don't understand: handleChange = field => e => { e.preventDefault(); /// Do something here }
Oligopoly asked 25/9, 2015 at 13:6

9

Solved

I'm running lint with my React app, and I receive this error: error JSX props should not use arrow functions react/jsx-no-bind And this is where I'm running the arrow function (inside onClick): ...
Role asked 17/4, 2016 at 14:22

8

Solved

That is, how do I express function *(next) {} with arrow syntax? I've tried all the combinations I could think of, and I can't find any documentation on it. (I am currently using Node.js v0.11.14....
Carney asked 26/12, 2014 at 19:51

5

Solved

The typescript handbook on user defined type guards defines an example type guard as function isFish(pet: Fish | Bird): pet is Fish { return (<Fish>pet).swim !== undefined; } Is there a c...
Salimeter asked 16/12, 2017 at 15:6

3

Solved

can someone, please explain the following: I'm following Dan Abramov's lectures & doing the exercises. The code works fine, however, the tests fail when the following particular function is ...
Oversupply asked 16/2, 2016 at 18:24

2

Solved

I am trying to export a function in a .js file using both normal or arrow function. But I don't understand which is recommended. Export normal function module.exports = function(id) { console.lo...
Oscar asked 20/9, 2018 at 12:53

8

I am learning about react components following the documentation https://facebook.github.io/react/docs/state-and-lifecycle.html Why do we need to use arrow function here: this.timerID = setInterv...
Club asked 20/8, 2017 at 9:26

4

Solved

The new arrow functions in ES6, are like one-liner functions which make code more clean and concise, and also allow you to keep the scope of the caller inside the function, so that you don’t need t...
Nunci asked 13/3, 2017 at 20:27

11

Solved

I can mark a JavaScript function as "async" (i.e., returning a promise) with the async keyword. Like this: async function foo() { // Do something } What is the equivalent syntax for arr...
Bonnard asked 22/3, 2017 at 22:50

1

interface Foo1 { (param: number): number (param: string): string } const foo1: Foo1 = (param: number | string) => param as any const foo2 = <T>(param: T) : T => param interface Foo...
Lodmilla asked 6/2, 2019 at 1:43

3

Solved

PHP 7.4 introduced Arrow functions. And it also introduced implicit by-value scope binding which eliminate the need for use keyword. Now if we want to use a variable out of a closure's scope by re...
Primateship asked 28/11, 2019 at 6:48

2

Solved

I'm trying to document my code with JSDoc (EcmaScript 2015, WebStorm 12 Build 144.3357.8). I have an arrow function which I want to document its parameters. This two examples work (I get auto-compl...
Coleoptile asked 31/1, 2016 at 9:45

7

Solved

I'm having some issues understanding why I'm getting a compile warning on this piece of my react code fetch('/users') .then(res => res.json()) .then(data => { data.map(users => { cons...
Monolayer asked 9/1, 2018 at 8:4

3

Solved

Does anyone know how to write an immediate function using ES6 arrow syntax? Here's the ES3/5 way of doing it: (function () { //... }()); I've tried the following but get an unexpected token er...
Tillietillinger asked 3/3, 2014 at 4:12

3

Solved

Ok, I have the following scenario: type IHashFn = (arg: string) => number; const hash: IHashFn = (arg) => { return 42; } So far, so good. Now I want the function to be generic. const has...
Rockbottom asked 22/4, 2020 at 22:42

© 2022 - 2025 — McMap. All rights reserved.