Giter VIP home page Giter VIP logo

Comments (3)

errorrik avatar errorrik commented on August 16, 2024

If the dependencies argument is omitted, the module loader MAY choose to scan the factory function for dependencies in the form of require statements (literally in the form of require("module-id")).

from esl.

killeryyl avatar killeryyl commented on August 16, 2024

抱歉,我是在define里用的动态加载概念。代码里不明确指定需要哪些模块,而是根据交互后提供的参数来确定加载模块。这样用变量名的require方式就不能被正确的预处理加载(这倒是保证了里里外外的模块都能加载完毕),使用的时候会出错。如果判断不存在时在尝试加载,貌似也不是什么好方法,目前也不大肯定这里值不值得动刀。看以后业务里的使用情况吧。

from esl.

errorrik avatar errorrik commented on August 16, 2024

抱歉,我是在define里用的动态加载概念。代码里不明确指定需要哪些模块,而是根据交互后提供的参数来确定加载模块。这样用变量名的require方式就不能被正确的预处理加载(这倒是保证了里里外外的模块都能加载完毕),使用的时候会出错。如果判断不存在时在尝试加载,貌似也不是什么好方法,目前也不大肯定这里值不值得动刀。看以后业务里的使用情况吧。

如果是希望动态的话,应该使用require({Array}modules, {Function}callback)接口

但是我们曾经讨论过这个问题,最后认为,碰到这种场景,大多数情况应该认为当前模块依赖于两个模块,都加载。也就是:

var mod;
if (...) {
    mod = require('modA');
}
else {
    mod = require('modB');
}

from esl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.