DEV Community

Discussion on: Power of window object in javascript

Collapse
 
tiagojpdias profile image
Tiago Dias

Why not throw a debugger; statement wherever you need? And why are you suggesting people to pollute the global scope, risking to override builtin functions by mistake?

Collapse
 
nyxtom profile image
Tom Holloway πŸ•

I think what he is suggesting is being able to expose third party libraries to the console via window let’s you play around with input variations - effectively making these things more β€œrepl” like

Collapse
 
shubhamforu profile image
Shubham

Yes Tom, Correct. Generally whenever you need to play with third party library. Either you go to repl like site install and play with or install locally module. But at the same time if you are working in some project it irritates to switch context. Debugger is always there but at the same time most people are not comfortable with it. This post is for beginner or newbie who struggle alot. That's why I added disclaimer its just for testing purpose. There are always better method than this once you are proficient in code. Hope you got it @TiagoDias

Thread Thread
 
tiagojpdias profile image
Tiago Dias

I get the objective of doing what you did, I'm just trying to warn that people might be gunning their foot since they are less proficient in code and might do something like:

import Number from 'some-number-utils';

window.Number = Number;

And from here on they're overriding the Number global function and their app might not work as expected due to this override.

Maybe advise to wrap the global variable in __ like window.__<name>__ ?

I'm not against what you did, I'm just trying to warn for possible side effects.

Thread Thread
 
shubhamforu profile image
Shubham

Totally agree. Maybe some variable identifier is good idea. Thanks will update in post as well