Skip to content

Using curl.js with underscore

unscriptable edited this page Jan 10, 2012 · 10 revisions

Using curl.js with underscore

curl.js 0.6 added two new features that allow it to work with underscore. (underscore's AMD implementation isn't quite right because it calls define() before actually defining its methods and properties.)

You must map the path to underscore.js when configuring curl.js.

underscore registers itself as an absolutely named module. curl.js (as well as any other AMD loader) ensures that the correct module got loaded by comparing the id of the requested module with the module that was actually loaded. Since underscore registers itself with the name, "underscore", all modules that list underscore as a dependency must also refer to it by the exact same name. Trying to refer to underscore as any of the following module ids will fail:

  • "js/vendor/underscore/underscore" (BAD: path is included)
  • "Underscore" (BAD: capitalization is different)
  • "underscore.1.2.1.min" (BAD: extra filename bits)

The best way to ensure all code can correctly refer to it as "underscore", you should add the following path mapping to curl.js's config:

paths: {
	"underscore": "js/vendor/underscore/underscore.1.2.1.min"
}

For more information about paths, see Understanding Paths.

_ is no longer available as a global variable.

If your code -- or third-party code -- relies on the _ global variable, they will fail. When loaded as an AMD module, underscore will not create this global. To fix this, your code and any third-party code you're using should be rewritten as modules.

For more hints about using underscore, check out the Using curl.js with jQuery page. Much of the information on that page applies to underscore, as well.

## ### 1.

Clone this wiki locally