문제

When writing an application using RequireJS the reuired files are stating their dependencies using the define( ['actual dependency name'], function (dependency, variables, ...) {}) which is all nice and dandy for using just one or two, but once you start having deeper dependencies it become a little bit complicated and not very readable or maintainable, i.e.:

define(['modules/module1', 'modules/module2', 'modules/module3', ...],
    function (module1, module2, module3, ...) {});

If I add or remove a dependency I have to rewrite my arguments list in the callback function as well, again - not very maintainable...

Is there a better method of doing this? Am I missing something very simple?

도움이 되었습니까?

해결책

Yes, you can be explicit like this:

define(function (require) {

    var depA = require('depA'),
        depB = require('depB'),
        depC = require('depC');

    ...
});

which should alleviate your maintenance trouble ;)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top