Questions tagged [arrow-functions]

Questions about the compact function syntax in ECMAScript2015 (ES6) called "arrow functions" because of their use of "=>".

"Arrow functions" are a compact syntax for function definitions in ECMAScript 2015 (ES6).

Arrow functions differ from regular functions in several ways:

  • They cannot be named. They are anonymous only.
  • They are not constructors, don't have a .prototype and cannot be instantiated by new.
  • They use lexically scoped this instead of binding this dynamically on the call

Arrow functions are also available in CoffeeScript.

1520 questions
-2
votes
2 answers

Write a javascript function count(arr, callback). It should return the number of elements for which the callback(an arrow function) is true

For example: count([2, 1, 4, 5, 2, 8], (e) => e === 2) // Expected: 2 count([1, 2, 3, 4], (e) => e > 1) // Expected: 3 It is also necessary to use forEach What I have: function count(arr, callback) { let values = 0 arr.forEach(cb ?…
ju_ro
  • 37
  • 3
-2
votes
3 answers

how to convert function into es6 arrow function

i need to write below function into arrow function using ES 6 . below i have given function.in reactjs // tab_Row(){ return this.state.business.map(function(object, i){ return ; }); }
pavan kp
  • 69
  • 1
  • 4
  • 13
-2
votes
1 answer

JavaScript: Equivalent of arrow function (how to not use an arrow)

I am new to JavaScript, and I am struggling with how to change an arrow function with non-arrow function... Please help, and thank you very much in advance! this.middleware(req,res,()=>{ this.processRoutes(req,res); });
Nathan Bell
  • 167
  • 1
  • 14
-2
votes
3 answers

what do small brackets means in reactjs

const layout = (props) =>(
Toolbar, SideBar, BAckdrop

hi

) my app component class App extends Component { render() { return (
-2
votes
1 answer

“Arrow function” in Array.from and forEach does not work in IE 11 it throws a syntax error in the console.how to solve?

below the codes does not work in IE 11 it throws a syntax error in the console how to fix codes for IE 11? function range(start, end) { return Array.from(Array(end - start + 1), (_, i) => i + start); } & getPageList(totalPages, currentPage,…
Myat Su
  • 27
  • 3
-2
votes
1 answer

About semicolon in ES6 when using return

I'm new to JS. If I add a semicolon like this ${this.name} is friends with ${el}; I'll get an error "Uncaught SyntaxError: missing ) after argument list". May I know why? Since in ES5, I can use semicolon like return this.name + ' is friends with '…
Ying
  • 299
  • 1
  • 5
  • 20
-2
votes
1 answer

How to use arrow functions inside other functions?

the full code is in the link I am to trying declare an arrow function by assigning it to the variable randomColor using the array.push() method, but I am getting the error "randomColor is not defined" when I run the code. Please help. function…
nishant
  • 117
  • 3
  • 13
-2
votes
3 answers

Using JavaScript arrow function iterate an array and create array inside array based on conditions?

I have an array like the below. [{ id: 1, is_child_question: false, parent_question_id: null }, { id: 2, is_child_question: true, parent_question_id: 1}, { id: 3, is_child_question: true, parent_question_id: 2}] I want to iterate…
-2
votes
3 answers

Can arrow functions be passed as parameters of repeat()?

While searching for arrow functions I came across this example let labels = []; repeat(5, i => { labels.push(`Unit ${i + 1}`); }); console.log(labels); // → ["Unit 1", "Unit 2", "Unit 3", "Unit 4", "Unit 5"] 1st, repeat method from MDN seems to…
leonardofed
  • 936
  • 2
  • 9
  • 24
-2
votes
2 answers

What is the correct arrow function syntax?

Arrow functions can be written in a lot of different ways, are there any way that is "more correct"? let fun1 = (a) => { return a; } let fun2 = a => a; Just like those cases above, is fun2 faster then fun1? What's the diference between them?
Gabriel Carneiro
  • 643
  • 5
  • 16
-2
votes
2 answers

can't setState in a function inside a arrow function on React

I'm trying to use This inside a function on a arrow function. How can I use setState inside my function? showDeleteConfirm = commentId => { const { deleteComment } = this.props; const { comments } = this.state; // this exist …
Juan P. Ortiz
  • 568
  • 1
  • 6
  • 21
-2
votes
4 answers

How to use map and find together in Typescript?

I am trying to create an array of all string which has length more than zero. let sampleArray2:string[] = ["hello","world","angular","typescript"]; let subArray:string[] = sampleArray2 .map(() => sampleArray2 .find(val => val.length >…
codingsplash
  • 4,785
  • 12
  • 51
  • 90
-2
votes
2 answers

How would you write this without using arrow notation?

In my increaseCount method I have 3 different ways of increasing the count. I thought the first method could be used twice but it doesn't work as it seems to merge the setState in the callback. What's the proper way to use a callback function and…
DCR
  • 14,737
  • 12
  • 52
  • 115
-2
votes
2 answers

What is the difference between the functions (theory)

What is the difference between these functions: callback(x: string[], y: string[]){ console.log(x.concat(y).join(', ')); } and (c,d) => console.log(c.concat(d).join(', ')) ?
-2
votes
1 answer

How do I get a proper "this" when a class method is called by an external class with arrow functions?

See the example below. Inside of a callback A.handleEvent, I was expecting "this" to be an instance of A instead of B, even though it is being called from B. class A { constructor() { this.text = 'A'; this.b = new B(this); } …
1 2 3
99
100