This is an extract of the Backbone.js source (near the very top):
// Require Underscore, if we're on the server, and it's not already present.
var _ = root._;
if (!_ && (typeof require !== 'undefined')) _ = require(开发者_如何学运维'underscore')._;
At no point is require
defined. What is it?
In other words Backbone.js can be used with non-browser JavaScript backend languages that follow the CommonJS spec like Node.js.
Here's the bit about require in Node.js docs.
It's checking for the presence of require
from the CommonJS module specification. It's saying that if the global object doesn't contain _
, try to require the underscore
module (if require
is defined) and get _
from there.
精彩评论