News for hackers. Stuff that matters.
Re:Debugging Node.js in Production by jtmarmon on Friday December 04, 2015 @10:45AM (#10676908)
even more abused now w/ es6 arrow shorthand
Re:Debugging Node.js in Production by lewisl9029 on Friday December 04, 2015 @11:17AM (#10677152)
I wish named arrow functions made it into the spec.
Re:Debugging Node.js in Production by gotchange on Friday December 04, 2015 @11:33AM (#10677269)
A workaround for this to get the best of the two worlds:

    let func = () => {};
Re:Debugging Node.js in Production by ehynds on Friday December 04, 2015 @11:40AM (#10677311)
That seems to do it.

  let func = () => {};
  console.log(func.name); // func
and in stack traces:

  let func = () => foo();
  func()
results in:

  Uncaught ReferenceError: foo is not defined
  func @ test.js:1
Re:Debugging Node.js in Production by lewisl9029 on Friday December 04, 2015 @11:59AM (#10677428)
Wow. I had no idea that would work.

All this time I've been using the full named function expressions over arrow functions just for the stack traces.

Re:Debugging Node.js in Production by ehynds on Friday December 04, 2015 @12:30PM (#10677650)
Still though, in situations where I care about the stack trace, I don't see myself writing:

  let doStuffCallback = () => {};
  doStuff(doStuffCallback);
over:

  doStuff(function doStuffCallback() {
  });
Re:Debugging Node.js in Production by spamizbad on Friday December 04, 2015 @12:26PM (#10677626)
Does that only work with something like babel? Because using the node 5.1 repl (and chrome console) you get:

    > let func = () => {}
    undefined
    > func.name
    ''
    > function longfunc() {}
    undefined
    > longfunc.name
    'longfunc'
Re:Debugging Node.js in Production by lewisl9029 on Friday December 04, 2015 @12:45PM (#10677778)
The .name property doesn't seem to get set in Firefox either, but error stack traces do show the variable name as the function name. That's the important part IMO.
Re:Debugging Node.js in Production by gotchange on Friday December 04, 2015 @01:37PM (#10678134)
Have you tried it with a « var » instead as Chrome imposes certain restrictions on the new ES6 keywords?

I also checked the online Babel REPL and verified that it works fine.

Re:Debugging Node.js in Production by spamizbad on Friday December 04, 2015 @02:53PM (#10678673)
var results in the same behavior in chrome (empty string for a function name)

It looks like babel does this little nicety for stack-trace readability.

Re:Debugging Node.js in Production by gotchange on Friday December 04, 2015 @03:14PM (#10678833)
I think Babel converts the code to ES5 and then execute the statements and therefore the function's name is printed to the console just like what you expect from good old ES5 code.
Re:Debugging Node.js in Production by spamizbad on Friday December 04, 2015 @03:46PM (#10679017)
The most direct ES5 translation of

    let func = () => {}
would be

  var func = function() {}
But even in that case, func.name is going to be "".
Re:Debugging Node.js in Production by gotchange on Friday December 04, 2015 @04:21PM (#10679221)

    var func = function func() {};
That's what the Babel REPL spits when you input the « let » statement.
Re:Debugging Node.js in Production by Scarbutt on Friday December 04, 2015 @12:35PM (#10677681)
sadly, babel is taken for granted these days.
Re:Debugging Node.js in Production by merpnderp on Friday December 04, 2015 @12:39PM (#10677720)
Which is the same as var func = function(){...}.bind(this); no es6 required.
Re:Debugging Node.js in Production by ehynds on Friday December 04, 2015 @01:03PM (#10677900)
OP is saying that `let func = () => {};` creates a named function where func.name equals "func" and "func" appears as part of the stack trace.

Your example is still an anonymous function just bound to a different context.

Re:Debugging Node.js in Production by gotchange on Friday December 04, 2015 @01:33PM (#10678103)
and more verbose as well which was the concern of person to whom I replied.
Re:Debugging Node.js in Production by snappy173 on Friday December 04, 2015 @11:54AM (#10677402)
on the other hand, es6 classes encourage named methods ...