jashkenas / underscore

JavaScript's utility _ belt
https://underscorejs.org
MIT License
27.33k stars 5.53k forks source link

Take this from an isolated script context #2831

Closed jgonggrijp closed 4 years ago

jgonggrijp commented 4 years ago

Fixes #2827, in a way that will continue to work after the rollup conversion from #2826. As a bonus, it will also stop rollup from complaining about this being undefined at module scope.

@lohriialo this is version D, but with a cleaner commit history.

@jashkenas it might be possible to skip the self and global checks and just always rely on Function('return this')(), but I'll leave that as an optional future step.

jgonggrijp commented 4 years ago

@lohriialo and other ExtendScript users: until this is merged and released, you can just use the version D that I provided in #2827. It is equivalent to Underscore 1.9.2, but with the current fix as well as the fix from #2829.

jashkenas commented 4 years ago

I have a feeling like some overzealous linters may complain about the "insecure" use of eval after this change — but hey, let’s give it a try.

jgonggrijp commented 4 years ago

Thanks @jashkenas. At least the project's own linter doesn't complain.