开发者

What is `require` in the content of Backbone.js?

开发者 https://www.devze.com 2023-04-06 00:26 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消