Comments (6)
I think it's related to the change in https://github.com/requirejs/cajon/blob/master/tools/c.js#L41. Using global.eval
vs eval
.
When eval
is used, global
is provided via the scope chain, but global.eval
doesn't.
from cajon.
If you have an example or test case that shows what kind of module loading breaks, that would help figure out a solution.
from cajon.
Here's a CommonJS module to test global.
https://gist.github.com/GCheung55/5116931959a24afc1b2a
I just tried [email protected] and the issue is reproducible.
from cajon.
Looking more at this, while the behavior changed in #8, it was for correctness -- best not to leak the private variables inside the loader to the evaluated text, and to provide a consistent eval environment. So I would expect the behavior as typeof global
being undefined.
Is this more about compatibility with modules from node? If so, that is a trickier issue. Node has other implied available variables, like process
, but I was not planning on simulating a node environment with cajon, just providing an "unwrapped" modules in the style of CommonJS/Node. But just on the style of module APIs, not on their execution environment.
If this was needed, for a particular project, it can be provided outside the loader:
<script src="cajon.js"></script>
<script>
var global = this;
require(['app']);
</script>
Does that meet the goals?
from cajon.
True, I could add var global = this;
. I don't expect a complete simulation of a node environment. process
doesn't make sense to simulate, especially since there isn't an equivalent in a browser environment. But I think a global
equivalent in a browser environment would be window
.
How do you feel about exposing global as an argument to the module's callback?
define(function(require, module, exports, global){})
I ask because this would be a tiny bit more performant than looking up the scope chain in order to find global
set as a global variable.
from cajon.
Also, there are node modules that are written for both browser and server environments. The one I'm currently using is https://github.com/kamicane/prime/blob/master/defer.js which makes use of checking global
for properties/methods. It's treating global
as window
.
from cajon.
Related Issues (15)
- 'use strict' causing script loading errors. HOT 2
- Support require([js-data-uri]); HOT 1
- Cajon treats CoffeeScript compiler as a CommonJS module HOT 1
- Require-CS not working with Cajon HOT 3
- Remove Query from path in debugger... HOT 1
- `exportsPropRegExp` should also check for array notation.
- not working with text plugin HOT 9
- "exports is not defined" HOT 2
- Backbone shim HOT 4
- Not working with handlebars via the requirejs-handlebars plugin? HOT 3
- Evaled scripts show up under (no domain) in chrome
- Conditional comments around sourceUrl comment causing grey hair HOT 3
- Code has to be evaluated in global scope HOT 5
- Cajon is not available via Bower HOT 5
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 cajon.