question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Avoid Global Namespace

See original GitHub issue

I developed an embeddable widget which makes use of Pusher. Pusher is required from npm and my final js file is bundled using browserify.

As Pusher makes use of window.Pusher it is creating conflicts when the page using my widget is already making use of Pusher.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:13 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
mgalgscommented, Jan 25, 2017

if you go ahead and import pusher.worker.min.js in a script tag then you can rename window.Pusher to window.Pusher2 and everything works swimmingly.

Yep, that worked! Thanks for the workaround. I’ll be on the lookout for a more permanent solution.

1reaction
jpatel531commented, Jan 24, 2017

@mgalgs - could you try the worker build (pusher-js/worker)? This will work readily in the browser and does not (if memory serves) attach itself to the global namespace. The caveat is that it uses fetch for auth requests + sending stats to Pusher. This means on some older browsers (IE ≤ 11) and Safari, it will require a polyfill: https://github.com/github/fetch.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is “Don't Pollute the Global Namespace” Still Good Advice in ...
In an effort to prevent naming collisions, experts labeled this practice as “pollution of the global namespace”. Example of global namespace pollution:
Read more >
JS tip - Avoiding polluting the global namespace - BigBinary
Polluting global namespace is not good. This blog presents a better technique.
Read more >
How to avoid namespace pollution in Javascript
I found this brilliant post about namespace pollution, which notes that - beside of conflicting name definitions - using global variables ...
Read more >
Global NameSpace Pollution In JavaScript - Medium
In this article we will understand what is Global Namespace Pollution is in JavaScript and How to overcome this problem in javascript.
Read more >
What is global namespace pollution in JavaScript?
Polluting Global namespace causes name collision. This name collision is very common in large projects where we may be using several ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found