WickyNilliams / enquire.js

Awesome Media Queries in JavaScript
http://wicky.nillia.ms/enquire.js/
MIT License
3.62k stars 269 forks source link

do not pollute global namespace #97

Closed szepeviktor closed 7 years ago

szepeviktor commented 10 years ago

Could you please return only MediaQueryDispatch and not set window.enquire in AMD mode: https://github.com/WickyNilliams/enquire.js/blob/master/dist/enquire.js#L15 return (context[name] = factory(matchMedia)); would be return (factory(matchMedia));

Is it OK?

WickyNilliams commented 10 years ago

I can't say I know enough about AMD to be able to make a judgement call on this. I think I followed one of the UMD patterns, by the looks of it this one: https://github.com/umdjs/umd/blob/master/amdWebGlobal.js

There was a lot of discussion in issue #61

szepeviktor commented 10 years ago

What I was asking for it this: https://github.com/umdjs/umd/blob/master/amdWeb.js When AMD loaded it does not pollute the global namespace.

WickyNilliams commented 10 years ago

Thanks for getting back to me :)

I don't know whether it is a good idea to drop the global once it has been out in the wild? People may be relying on it, and removing from global may cause them issues.

Is it causing you issues, or is it a suggestion just for best practice?

WickyNilliams commented 10 years ago

Reopening as it's worth discussing further...

szepeviktor commented 10 years ago

"best practice" and for "not to write js lib that pollutes global namespace"

WickyNilliams commented 7 years ago

I am now using browserify to generate the UMD wrapper, so it should no longer pollute the global namespace. And as I wrote that, I just realised means that I've introduced a breaking change on a patch release... Ah well

szepeviktor commented 7 years ago

Thank you for your work!