Comments (14)
In node.js modules, this === module.exports
. Changing that would break any node modules that currently use this
this way.
from browser-pack.
from browser-pack.
@mscdex @epeli thanks for the additional info.
I am empathic to this point made by @epeli earlier
On the other hand I've never seen anyone using this to export stuff from node.js modules. People are always using exports or module.exports explicitly. Assigning this to window could be very practical for non-CommonJS libraries, but it wouldn't be the most node.jsish way.
I personally wasn't even aware that this
was bound to module.exports
in Node, and I am no newb. I just haven't seen this recommended or documented anywhere. Does anyone know of an active module which actually uses this
instead of module.exports
?
I am currently working on making deamdify work with a larger set of libraries, and as you can imagine, authors who publish in AMD may not be clued in to how Browserify/Node works.
from browser-pack.
Remember to think about the worst case too: When you actually encounter a module that uses this
to expose stuff and you browserify that module you get very sneaky global leaks...
Personally I'd say no to this request.
from browser-pack.
This would break a lot of node code in the browser.
from browser-pack.
Okay. I'll opt for the workaround of wrapping the amd modules with an iife.
from browser-pack.
Okay, so how should library address window to be compatible with browserify?
Just ran into issue related to this
in eligrey/FileSaver.js#57 and would appreciate any insights on how to address the matter in case script to need to access to window variable while being used with browserify.
from browser-pack.
@Sudoki Just use window
instead of this
. I never got why people don't just do that.
from browser-pack.
I wonder if browserify-shim transform can have a configurable option to wrap such "modules" into a function which executes in window's context? /cc @thlorenz
from browser-pack.
@substack some older libs still use this
cause they expect to run on script level. It makes it hard to use those with browserify
even with browserify-shim
. Even though that is not browserify
s fault, if there was a way to make this work out of the box that'd be great.
@andreypopp I'd rather find a solution that works for all modules. If you think this can (and should) be solved via browserify-shim
, please file an issue (ideally with repro case) over there and we can figure out how to do that.
from browser-pack.
The workaround I used was:
;(function(){
// original code
}.call(window));
from browser-pack.
Since this is very browser specific, adding it to browserify would break things in node (you can run a bundle in node).
Would this problem be solved if browserify-shim would wrap modules like this? Possibly the issues appear most likely when shimming modules?
from browser-pack.
@thlorenz yeah, that's what I mean, it would be done before being passed to browserify.
from browser-pack.
So we'll fix it in browserify-shim then.
I'd appreciate an issue with a repro case in the browserify-shim issues :)
from browser-pack.
Related Issues (20)
- IE8 global variable leak. HOT 4
- `npm install --production` fails HOT 1
- Broken testling badge HOT 2
- semicolon not added to the end of the generated file HOT 3
- Why are all modules required by the prelude? HOT 2
- Support dynamic standalone module name, based on source file name
- Not able to use standalone & require flags at the same time HOT 11
- JSONStream vs. jsonstream
- Why not avoid the same module run multiple times when more than one other modules require it. HOT 2
- Problem about almond require HOT 6
- Need update combine-source-map module. HOT 1
- Why not update uglify-js in devDependencies from "1.3.5" to "2.x.x"? HOT 2
- DeprecationWarning on node 7 HOT 6
- Upgrading combine-source-map for Windows issue
- Why are we passing extra arguments to the module creating code? HOT 2
- browser-pack is not compatible to Opera/10.x
- How to compile with newer uglify (patch) HOT 1
- Include source map alongside prelude
- add a test using browser-unpack
- From debian use uglifyjs > 3.12.4 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from browser-pack.