And every difficult to debug bug hasn't been related to knowing which functions are in the stack, but are instead related to figuring out why frameworks do something or race conditions and so on.
I just find it surprising that people are having problems with anonymous functions in stack traces, when I've never seen that.
As someone just delving into Node from another platform what're "proper best practices"-based JS patterns?
It's telling that, while you do often see Javascript (not JScript, which is a Microsoft product and quite obsolete) developers pull some crazy nonsense with deeply nested lambdas, you almost never see Javascript developers do that in an environment that requires peer code review.
I've come across many JavaScript devs casually using and advising interns, etc to use anon functions to avoid cluttering code. It was almost preached as a design pattern. I was taken aback (as a back-end dev), but given the crazy stuff most JS devs did I just shrugged it is one of the platforms' quirks.
Using lambdas in the fashion you describe is a dangerously poor practice that, over the long run, produces code that's much harder to maintain than it should be. That's why you don't see it in environments where changes have to pass peer review by experienced Javascript engineers before being accepted into the codebase. Unfortunately, such environments are far from prevalent and the JS dev world lacks rigor even by comparison with web development as a whole, so you see a lot of people abusing lambdas and encouraging others to do likewise. That doesn't make it any less a bad idea.
Are there any other such bad practices in the JS dev world? I've only just considered moving onto Node as I've grown disillusioned with Rails and the concept of using a single language across the entire app & mobile (React Native, etc) sounds enticing.
I'd also suggest that it's worth your while to take advantage of the JS dev community's excellent culture around automated testing; while that's a slightly more complicated topic, it is only slightly so, and I've found that a solid test suite, plus a coverage tool to ensure it doesn't leave anything out, is even better for improving and maintaining code quality than just a linter by itself -- jshint can catch stylistic and structural errors, but only unit tests will catch logic errors and regressions introduced by a new change. If you're (understandably) bewildered by the variety of testing tools available -- it seems like somebody comes out with a nifty new one every week or so -- then I'd suggest you can hardly go wrong with these:
* jshint, as already described
* Mocha, a flexible and reliable test framework
* Istanbul, a coverage report generator
* Grunt, a build tool whose plugin architecture simplifies integrating them
For an example of how they work together, you might take a look at https://github.com/aaron-em/same-encoder, where I use them all in support of a library providing functionality which I think is neat and probably no one else cares about. No doubt there are much better examples, but none come to mind quite so readily, and this codebase being as small as it is, it should be able to serve as a decent overview without being so big you'll get bogged down in it. In particular, /Gruntfile.js demonstrates how to tie all these disparate tools together for quick invocation with a single command like 'grunt validate', which I find makes it a lot more likely I will actually remember to run them; also take a look in /test/unit for an example of how Mocha tests are actually written.
https://facebook.github.io/react/docs/reusable-components.ht...
using Chrome + React Dev Extensions
setting up sourcemaps to work properly is quite a pain though, most the browserify tooling via gulp or grunt does a pretty poor job of it.
I only get proper sourcemaps if I use the tsify plugin + setting browserify debug=true. adding anything else causes sourcemaps to go out-of sync. That's OK though, as I get good sourcemaps in development and can live without it when in production.
Some complaints I see about Python's weak lambda have a similar undercurrent.
For example: if(objects.find(object => object.id === id)) {}
You can have lambdas that are also named, e.g:
if(objects.find(function idCheck(object){ return object.id === id})
Not sure if it's possible with the new ES6 syntax [Edit: apparently it's not, although arrow functions will automatically be assigned a name in some common scenarios].
The main purposes of fat arrow functions is the auto-binding of this and succinctness.
A named fat-arrow function would still retain both, and in fact the feature was considered for ES6 back in 2013, but didn't made it. Syntax would have been like:
if(objects.find(functionName(object) => object.id === id)) {}
Signed: someone who occasionally has to maintain a massive CoffeeScript clusterfuck. If you want to be trendy that bad, buy a turtleneck. Don't use CoffeeScript.
let func = () => {}; 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:1All this time I've been using the full named function expressions over arrow functions just for the stack traces.
let doStuffCallback = () => {};
doStuff(doStuffCallback);
over: doStuff(function doStuffCallback() {
}); > let func = () => {}
undefined
> func.name
''
> function longfunc() {}
undefined
> longfunc.name
'longfunc'I also checked the online Babel REPL and verified that it works fine.
It looks like babel does this little nicety for stack-trace readability.
let func = () => {}
would be var func = function() {}
But even in that case, func.name is going to be "". var func = function func() {};
That's what the Babel REPL spits when you input the « let » statement.Your example is still an anonymous function just bound to a different context.