cujojs / curl

curl.js is small, fast, extensible module loader that handles AMD, CommonJS Modules/1.1, CSS, HTML/text, and legacy scripts.
https://github.com/cujojs/curl/wiki
Other
1.89k stars 216 forks source link

Unbundled CommonJS module evaluation and `"use strict";` #183

Closed unscriptable closed 11 years ago

unscriptable commented 11 years ago

According to this jQuery ticket by @jdalton, "indirect eval" fails to offer the proper "use strict"; behavior. Consider switching the default configuration option (injectScript) to true to use script injection instad of indirect eval.

Code: https://github.com/cujojs/curl/blob/master/src/curl/loader/cjsm11.js#L101

This is only an issue with unbundled commonjs modules, which are loaded via XHR.

jdalton commented 11 years ago

I actually like the ES5 "use strict" eval feature, it's just if the goal is global eval'ed code it won't work with an indirect eval call of a string containing a valid "use strict" directive.

rwaldron commented 11 years ago

This is not a "failure", http://bugs.jquery.com/ticket/13714#comment:13

unscriptable commented 11 years ago

Ok, iiuc, evaling code that contains "use strict"; inside a global eval will cause the global scope to become strict. Evaling code that contains "use strict"; inside a script element does not change the global scope.

jdalton commented 11 years ago

inside a global eval will cause the global scope to become strict.

It'll cause the code to be executed as if it's inside an IIFE.

unscriptable commented 11 years ago

closing since we always wrap in a function () {}. thanks guys.

jdalton commented 11 years ago

no prob hann, or hamm, no hann.

tumblr_m8dk7rPxi11qhv4q1o1_500