News for hackers. Stuff that matters.
Re:Lodash 4.0.0 is out by HNcow on Tuesday January 12, 2016 @07:39PM (#10891517)
Not sure if this is a dumb question but I haven't been able to find an answer anywhere.

I currently use underscore 1.8.3. Can I just swap lodash in, or is refactoring involved? I know it's a fork, and I want to move over, but was curious if anyone know off the top of their heads if a lot of work as involved.

Re:Lodash 4.0.0 is out by ne8il on Tuesday January 12, 2016 @07:52PM (#10891558)
I haven't looked over the changelog/breaking changes for 4.0.0, so this may not encompass everything there, but there are a few changes you need to be aware of. How hard it is depends on which functions you use currently, but I doubt it would take more than an hour of find-replace work. They are listed here : https://github.com/lodash/lodash/wiki/Migrating The ones that affected me the most were the changes to the overloaded _.first, _.last, etc, but YMMV.
Re:Lodash 4.0.0 is out by krat0sprakhar on Tuesday January 12, 2016 @08:00PM (#10891596)
I've done similar refactorings in the past (somehow my fingers only remember `npm install underscore`) and for me it has always been a drop-in replacement. However, as others have pointed out, it does depend on how much functions you are using and from my experience the whole thing should not take long.
Re:Lodash 4.0.0 is out by kevindeasis on Tuesday January 12, 2016 @07:42PM (#10891524)
I'll put this here just in case no one comments.

https://lodash.com/docs#forEach

http://underscorejs.org/#each

Re:Lodash 4.0.0 is out by johnhenry on Tuesday January 12, 2016 @08:46PM (#10891797)
If I'm correct, you're showing this as a counter example to prove that the two have incompatible APIs and are thus LoDash can't be used ad a drop in replacement. However, Lodash does alias it's 'forEach' function with 'each', so this wouldn't be an issue?
Re:Lodash 4.0.0 is out by ksherlock on Tuesday January 12, 2016 @09:15PM (#10891914)
underscore.each has an optional 3rd parameter (context). lodash.each does not. If you depend on that 3rd parameter, you will be in a world of pain if you drop-in lodash. In fact you'd be better off if there was no alias because you would catch the problem sooner and have to think about the API differences when fixing it.
Re:Lodash 4.0.0 is out by 9point6 on Wednesday January 13, 2016 @08:38AM (#10894131)
To be fair, that context parameter has only just been removed as part of 4.0.0. Instead they recommend you change your code to be of the form:

    _.each(collection, _.bind(function, context))
Which actually seems a lot more correct than some arbitrary context parameter
Re:Lodash 4.0.0 is out by vkjv on Wednesday January 13, 2016 @09:49AM (#10894628)
How is it arbitrary? It's part of the ES spec.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

I'm honestly curious why this is being removed?

Re:Lodash 4.0.0 is out by 9point6 on Friday January 15, 2016 @09:26AM (#10909458)
Ah, I actually didn't realise this was the case, I've always used `.bind(this)` for this kind of thing.
Re:Lodash 4.0.0 is out by tdumitrescu on Tuesday January 12, 2016 @08:58PM (#10891841)
Yeah, each and forEach are aliases in both lodash and underscore.
Re:Lodash 4.0.0 is out by jdd on Thursday January 14, 2016 @04:44PM (#10904760)
Lodash v1 was a drop-in Underscore replacement.

Lodash v2 was not but offered an lodash.underscore.js build.

Lodash v3 dropped the compat build in favor of using individual lodash modules until you're able to transition

Lodash v4 continues the view of v3

Re:Lodash 4.0.0 is out by patates on Wednesday January 13, 2016 @04:54AM (#10893279)
Well, do you have tests? It would take 10 minutes if you are well-covered. Otherwise, I'd go through each usage.