Return object from arrow function

Stepan Suvorov

I want to output object from arrow function (in a short form), so full code is:

somemethod(function(item) {
   return {id: item.id};
})

with arrow functions it's:

somemethod((item) => {
   return {id: item.id};
})

and now short form should be something like:

somemethod(item = > {id: item.id} )

that does not work, as well as this one:

somemethod(item = > {{id: item.id}} )

only one solution I found for now is to use create Object notation:

somemethod(item = > new Object({id: item.id}) )

is there another way?

Sergiy Pereverziev
somemethod(item => ({ id: item.id }))

Test:

> a = item => ({id: item.id})
< function item => ({id: item.id})
> a({ id: 5, name: 7 });
< Object {id: 5}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Return object from arrow function

From Java

How to return anonymous object from one liner arrow function in javascript?

From Dev

Return an object from a function

From Dev

Return an object from a function

From Dev

How do you return an object with a fat arrow function without rebinding this?

From Dev

golang return object from a function

From Dev

Arrow Function in Object Literal

From Dev

Arrow function in Javascript Object

From Dev

Arrow function error: Object is not a function

From Dev

Arrow function with return in reduce call

From Dev

How to return a dynamic object from operator function?

From Dev

Can't return a temporary object from function

From Dev

How do you return an object from a function?

From Dev

How to return dynamic object from operator function?

From Dev

JQuery getJSON return object array from function?

From Dev

Return object from class function call

From Java

Refactor: Expected to return a value at the end of arrow function

From Java

Specify return type in TypeScript arrow function

From Dev

Expected to return a value at the end of arrow function with if statement

From Dev

Accepting a destructured object as the only argument to an arrow function

From Java

ECMAScript 6 arrow function that returns an object

From Dev

JavaScript: Multi line arrow function that returns an object

From Dev

Migrating to Arrow function from Normal function JS

From Dev

Return Object Outside of Function

From Dev

Expose function and return object

From Dev

Return an object with a function

From Dev

Howto examine return value from object function in a core?

From Dev

return an pointer to an object from a function without using new to allocate the pointer

From Dev

How to deduce the return type of a function object from parameters list?

Related Related

  1. 1

    Return object from arrow function

  2. 2

    How to return anonymous object from one liner arrow function in javascript?

  3. 3

    Return an object from a function

  4. 4

    Return an object from a function

  5. 5

    How do you return an object with a fat arrow function without rebinding this?

  6. 6

    golang return object from a function

  7. 7

    Arrow Function in Object Literal

  8. 8

    Arrow function in Javascript Object

  9. 9

    Arrow function error: Object is not a function

  10. 10

    Arrow function with return in reduce call

  11. 11

    How to return a dynamic object from operator function?

  12. 12

    Can't return a temporary object from function

  13. 13

    How do you return an object from a function?

  14. 14

    How to return dynamic object from operator function?

  15. 15

    JQuery getJSON return object array from function?

  16. 16

    Return object from class function call

  17. 17

    Refactor: Expected to return a value at the end of arrow function

  18. 18

    Specify return type in TypeScript arrow function

  19. 19

    Expected to return a value at the end of arrow function with if statement

  20. 20

    Accepting a destructured object as the only argument to an arrow function

  21. 21

    ECMAScript 6 arrow function that returns an object

  22. 22

    JavaScript: Multi line arrow function that returns an object

  23. 23

    Migrating to Arrow function from Normal function JS

  24. 24

    Return Object Outside of Function

  25. 25

    Expose function and return object

  26. 26

    Return an object with a function

  27. 27

    Howto examine return value from object function in a core?

  28. 28

    return an pointer to an object from a function without using new to allocate the pointer

  29. 29

    How to deduce the return type of a function object from parameters list?

HotTag

Archive