openexchangerates / accounting.js

A lightweight JavaScript library for number, money and currency formatting - fully localisable, zero dependencies.
http://openexchangerates.github.io/accounting.js
MIT License
4.96k stars 530 forks source link

AMD module loading do not seems to work #55

Open yamsellem opened 11 years ago

yamsellem commented 11 years ago

We are using accounting 0.3.2 with requirejs 2.0.6: accounting is properly loaded but it is not accessible like Underscore or Backbone.

Replacing the last lines of the script with those used in Underscore.js makes everything work:

if (typeof exports !== 'undefined') {
    if (typeof module !== 'undefined' && module.exports) {
        exports = module.exports = lib;
    }
    exports.accounting = lib;
} else {
        root.accounting = lib;
}
kmiyashiro commented 10 years ago

The whole point of modules is not to add a global, it is working as intended. Backbone is doing it wrong and underscore does not attach itself to global.

yamsellem commented 10 years ago

This issue (grabbed from its 2012's grave) is offering a working solution to the incompatibility of accounting and AMD (I don't even know is the 0.4 release have fixed this). Saying that this solution is not good without offering an alternative seems counterproductive to me.

kmiyashiro commented 10 years ago

As of 0.3.2, this is the code I see, which works fine with AMD:

    } else if (typeof define === 'function' && define.amd) {
        // Return the library as an AMD module:
        define([], function() {
            return lib;
        });
    }