这是indexloc提供的服务,不要输入任何密码
Skip to content

Definitions declaring a global var create collisions & global-shadow #1564

@Bartvds

Description

@Bartvds

From another thread: #1562 (comment)

I see many definitions declare a global variable, with the name most commonly used. For example jQuery defines $, and many other do similar.

Problem: the namespace for short identifiers is not unlimited. If these are used a lot it can potentially make it impossible to mix modules. So if you have a half-migrated test suite using two different assertion libraries that both declare a global var assert.


Even worse: if you use a definition with a global var but due to the way you use it it never gets initialised (because run it in node.js or use an AMD loader), then you have a global var shadowing your scoped usage (as seen by the compiler).

That is not good if you accidentally use it without actually initialising it at runtime. Then what you think is a scoped var gets attached to the global/window object (unless you lint, but who lints compiler output?)


And of course: once you use a definition with a specific global var then you loose your own use of that identifier in your own global scope, even if you never need the global var (because you use import or whatever)


Not sure what to do with this.

It feels unclean 😷. Maybe the users should declare their own var for the few cases where they actually use a global?

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions