Javascript AMD Modules: How to get Visual Studio intellisense across modules

别等时光非礼了梦想. 提交于 2019-11-29 19:52:03

问题


After looking into Asynchronous Module Definition (AMD) in the javascript context I was wondering how to get intellisense in Visual Studio 2010 for a dependent module.

For example given module A:

define(function() {
    return {
        square: function(value) {
            return value * value;
        }
    };
});

and a corresponding module B:

define(["A"], function(a) {
    return {
        value: a.square(10)
    }
});

Then I would like to have full intellisense for the module A (represented as parameter a) within module B. Note that both of these modules would be defined in separate files (A.js and B.js in this case).


回答1:


It looks like the author of RequireJS is working on Intellisense support here: https://github.com/jrburke/requirejs-intellisense

Unfortunately I haven't gotten the "magic" to work yet.

Update: I did get this to work in certain scenarios. In particular it works great when all of the js files are in the same folder.




回答2:


This comment here helped me get it to partially work: Comment on GitHub Repo

Basically, I had to make sure that this:

/// <reference path="require.js" />

is at the top of the _references.js file. It works in 'require' and 'define' blocks, but doesn't seem to work inside of anonymous functions within 'define' blocks.



来源:https://stackoverflow.com/questions/10167621/javascript-amd-modules-how-to-get-visual-studio-intellisense-across-modules

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!