Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Optionally registers as AMD module #1333

Merged
merged 1 commit into from

6 participants

@jrburke

As requested by @jashkenas, he wanted to see what adding an optional AMD registration would look like today. This is based on the version used in https://github.com/amdjs/underscore, but more comments to help explain the specific style used.

@iammerrick

Wahoooo!

@AjaxSolutions

About time!

@SBoudrias

Yes please!

@jashkenas jashkenas merged commit 82f9350 into from
@kebot

How about split functions into amd module(just like jQuery).

@TheBox193 TheBox193 referenced this pull request in pathable/supermodel
Closed

require.js compatibility? #26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 6, 2013
  1. @jrburke
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 0 deletions.
  1. +12 −0 underscore.js
View
12 underscore.js
@@ -1284,4 +1284,16 @@
});
+ // AMD registration happens at the end for compatibility with AMD loaders
+ // that may not enforce next-turn semantics on modules. Even though general
+ // practice for AMD registration is to be anonymous, underscore registers
+ // as a named module because, like jQuery, it is a base library that is
+ // popular enough to be bundled in a third party lib, but not be part of
+ // an AMD load request. Those cases could generate an error when an
+ // anonymous define() is called outside of a loader request.
+ if (typeof define === 'function' && define.amd) {
+ define('underscore', [], function() {
+ return _;
+ });
+ }
}).call(this);
Something went wrong with that request. Please try again.