Using RequireJS, how do I pass in global objects or singletons around?
问题 Let's say I am writing code at the main page level and 2 dependencies require the same instance of an object and also state that as a dependency. What is the appropriate way to go about this? Basically what I want to do is say, "If this dependency isn't loaded... then load it. Otherwise, use the same instance that was already loaded and just pass that one." 回答1: You would make that a module-level variable. For example, // In foo.js define(function () { var theFoo = {}; return { getTheFoo: