Skip to content

Use Function("return this") to get global? #2152

Description

@creatorrr

Underscore currently breaks in 'strict' mode while trying to access properties on the global object. The global object is being set using the (function(root) { ... })(this) pattern. However, in this case, root remains undefined and hence the issue.

Using the Function("return this")() pattern instead alleviates the issue, though arguably ugly. Thoughts?

Steps to reproduce: Import underscore in a babel-jest test harness. (uses strict mode)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions