-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't use window object #9
Conversation
The window object doesn't exist in all JavaScript contexts, e.g. Web workers.
|
|
But (function (window) {
})(this); I remember there were some issues with this approach too (when including Leaflet in browserify or something), @tmcw, comments? |
I usually rely on umd template to do the right thing and it does. |
We are using an adapted UMD template in Terraformer to make sure thing work in both node and browser environment. This seems to work pretty well, here is the code... (function (root, factory) {
// Node.
if(typeof module === 'object' && typeof module.exports === 'object') {
exports = module.exports = factory();
}
// Browser Global.
if(typeof window === "object") {
root.Terraformer = factory();
}
}(this, function(){
//export stuff
return exports;
})); |
OK, found the Leaflet commit by @jfirebaugh Leaflet/Leaflet@e699894 |
Yes, IIRC the leaflet change was necessary because it wanted to access actual |
|
Wow, I thought it was defined... Thanks Konstantin. Added export through self. |
BTW, regarding the export through |
The window object doesn't exist in all JavaScript contexts, e.g. Web workers.