bestiejs / json3

A JSON polyfill. No longer maintained.
https://bestiejs.github.io/json3
Other
1.02k stars 150 forks source link

Anonymous define #63

Closed nariman-haghighi closed 10 years ago

nariman-haghighi commented 10 years ago

Is it possible to replace define(function () { return A }) with define("json3", function () { return A })? It's wreaking havoc havoc with other requirejs scripts on page

https://github.com/keenlabs/keen-js/issues/112#issuecomment-49929276

bnjmnt4n commented 10 years ago

I’m not too sure about this myself as I don’t use RequireJS, but we encountered this recently with r.js (see #62). @kitcambridge what do you think?

ghost commented 10 years ago

It's a backward-incompatible change, but I think it's reasonable, especially if it's causing interoperability issues. The named export would require consumers of the library to add a mapping to their paths config, right?

I seem to recall there was a reason we removed the named export form in 421e8db4ba39e5c52695bce070c221d5c5df3b02, though. I'd love to hear from @unscriptable or @jaredcacurak before we do this.

unscriptable commented 10 years ago

Hey guys,

tl;dr: I think you should stay with an anonymous module.

Anonymous modules are preferred because they allow code to be refactored more easily and require less configuration. Named modules were meant to be used inside AMD bundles.

In the early days, people figured out that named modules had another benefit: they allowed folks to load UMD modules with <script> tags even if an AMD loader is present. This was a particularly awful problem when jQuery first supported AMD so it made sense at the time.

Please note: despite using named modules as a work-around for jQuery, it was -- and still is -- considered an anti-pattern to load AMD/UMD modules with <script> tags when an AMD loader is available.

I wouldn't call this an interoperability problem. Any architecture that mixes loader styles (e.g. <script> + AMD, browserify + AMD, RaveJS + browserify) is bound to encounter complexities and edge cases. Devs really need to commit to one style: either load all of your libs using <script> tags or use a loader.

Regards,

-- John

bnjmnt4n commented 10 years ago

I agree with @unscriptable’s comments; I’ll add a note about concatenating modules together.