Require js ruins code navigation

前端 未结 2 701
刺人心
刺人心 2021-02-05 07:54

require.js states the way of defining objects inside modules with define([requiremens], object) as best way.

So every page, or other js file, w

2条回答
  •  一向
    一向 (楼主)
    2021-02-05 08:54

    WebStorm (at least 6.0.2) supports code navigation with RequireJs if you're defining your modules with the CommonJs wrapper and use the exports and module arguments:

    //foo.js
    define(function(require, exports, module) {
        //use exports to expose properties for code navigation in other modules
        exports.bar = function() {}
    });
    

    Apparently, it works even if the module using it doesn't use the CommonJs wrapper format:

    define(['./foo'], function(foo) {
        foo.bar(); //code navigation works here
    }
    

    If the other IDEs use the same JavaScript plug-in as CrazyCoder said, it may work on their newer releases as well.

提交回复
热议问题