-5
10    const handle_request = (req) => {
20        req.command = "do something";
30        Addr = req.payload.addr;
40    };

60    request_handler = handle_request;

req seems to an internal variable but it's not included by the calling relation of line 60 and it appears no where else in the code. What does = (req) => do?

thanks

2 Answers2

0

Without using the ES6 syntax, that function would look like this

function handle_request(req) {
    req.command = "do something";
    Addr = req.payload.addr;
}
Benjamin Gil
  • 127
  • 1
  • 12
  • Makes way more sense, but I guess the other is required for a variable assignment? – michaelm700 Mar 14 '19 at 00:53
  • @michaelm700: No. Function *expressions* have existed since the beginning: `const handle_request = function() { ... }`. It doesn't matter anyway, the result is the same in this case. – Felix Kling Mar 14 '19 at 17:25
0

(req) => creates a function without name that takes parameter named req. After => goes body of the function with it's scope. These function called arrow function expression and you can read more about it here

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

max pinch
  • 1
  • 1