documentcloud/underscore — pull request #338 by jrburke (2011-10-18 23:36:01+00:00)
Title: Optionally call AMD define() to register module

This issue has come up before, in Issue #287. This pull request is different in these two aspects:

* The patch itself is different, doing it optionally as part of the global registration branch.
* I can provide more context on why this is useful to do.

## Patch

It is done as part of the "set global" branch, and it does not interfere with that branch, just optionally calls define if it is available. So this should not cause issues with code that still wants to use underscore as a global even when an AMD loader is on the page.

## Context

In the previous pull/issue there were concerns that a global define not being part of too many useful JS runtimes.

define() is part of the AMD API which is being adopted by a few toolkits like Dojo, MooTools and EmbedJS. jQuery 1.7 will include a very similar opt-in define() call as specified in this patch. define()-based code can run in Node via the requirejs package, and define() can be used in jetpack/add-on SDK add-ons for Firefox. Firebug 1.8+ uses define().

[More reasoning and context for AMD](http://requirejs.org/docs/whyamd.html).