rh / lodash-rails

lodash for the Rails asset pipeline
MIT License
75 stars 10 forks source link

'this' in the wrong context (v4.0.0) #7

Closed peric closed 8 years ago

peric commented 8 years ago

I know this is just a wrapper around lodash, but also because of that reason I'm writing it here and not to the lodash repository, in case it has already been resolved.

Recently, we updated lodash-rails from v3.10.1 to v4.0.0, and this introduced problems with 'this' having a wrong context.

This happened while we were using a _.each method. On the level where the method was called, there was a different this context then inside the method. To make it more clear, I'll write an similar example below.

console.log(this); // this will print out an object where method is called, in this just some custom object

_.each(extension, function(copy, key) {
    console.log(this); // even though this from above is passed to the each method, this one will print out a Window Object
}, this); // this from the context above is passed

As I mentioned, same thing works as expected in the v3.10.1 and it doesn't work in v4.0.0.

Would it maybe make sense to try update lodash-rails to latest stable 4.. version?

rh commented 8 years ago

I updated lodash to 4.3.0. I hope this solves it.

peric commented 8 years ago

Actually there were some breaking changes in v4.0.0 https://github.com/lodash/lodash/wiki/Changelog#v400.

_.each doesn't accept thisArgs anymore, some functions were renamed or dropped etc.

Thanks anyway, I've updated my code according to the breaking changes so now it's cool.