Closed bryanjswift closed 11 years ago
Overall I like this. I do have one question regarding the following line (and feel free to convince me otherwise)...
if (typeof module !== 'undefined' && module.exports) { module.exports = definition(); }
Is this line necessary? formatter.js runs strictly in a browser. Is there any advantage to exposing the definition via module.exports?
Thanks for the PR
I suppose that depends on what you call necessary. Just because formatter.js is runs in the browser does not mean people don't package their JS using the CommonJS modules style. I don't personally, I use RequireJS, but I do recall reading it is possible just as it is possible to use AMD style modules in Node.
I only have experience with AMD in the browser, and at the time of my comment, I was unable to find a CommonJS implementation. However, it does look like there are several (taken from http://addyosmani.com/writing-modular-js/):
I should offer the most flexibility possible. Merging. Thanks!
My pleasure. I should have provided examples of CommonJS implementations in my previous comment; apologies.
What's the correct way to use Formatter with jQuery in RequireJS?
For example, Backbone has Underscore as a dependency, and optional jQuery integration.
I just do:
require('jquery','underscore','backbone') ...
and everything seems to work.
Now, I tried doing adding the jQuery version of formatter to my paths config and add it to my require
statement but I get an error:
Uncaught Error: Script error for "jQuery", needed by: formatter
Do you have to "shim" it as I've seen some people do around the net or is there a better way?
Defines Formatter as an AMD module if an AMD compatible define function is found in scope. Does the same for CommonJS and falls back to defining it as
window['Formatter']
. Tests all still pass.