问题
I'm currently refactoring some Javascript code we have and amongst other things I've changed it to make use of the revealing module pattern. The code is looking much tidier and it works fine but I can't see the functions anymore in the outline view. I see the top level namespace var as a var but you can't expand it to see the functions within.
Lets say the code used to look like this:
function myFunc1() {}
function myFunc2() {}
In this case you see both functions in the outline view. But if you change it to this:
var myNamespace = function()
{
function myFunc1() {}
function myFunc2() {}
return {
name: "myNamespace",
myFunc1: myFunc1,
myFunc2: myFunc2
}
}();
Then the outline view just shows you the myNamespace var. I've tried looking but can't find a view that will actually show me the hierarchy correctly. Does anyone know of a way to view this or is it a case of eclipse not being able to do this?
回答1:
Add:
/**
* @memberOf myNamespace
*/
before each function definition to restore the hierarchy.
You will find more interesting tags to document your code here:
How I Introduced JsDoc into a JavaScript project – and found my Eclipse Outline
回答2:
one way is to call it as below. Define it as it is, but do not self execute it. Ensure the prototype is an empty object and then try calling it. It works the same way, but will restore the outline and you don't need to add comments in front of every function.
var myNamespace = (function()
{
function myFunc1() {}
function myFunc2() {}
return {
name: "myNamespace",
myFunc1: myFunc1,
myFunc2: myFunc2
}
});
myNamespace.prototype = {};
myNamespace();
回答3:
Not showing myFunc1() etc. in the outline appears to be a bug which is marked as fixed in 3.2. However it is not fixed in 4.2. It is certainly a huge pain when dealing with very large files of hundreds of functions, and only the var name shows up in the outline. I pray for it being fixed.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=236202
https://bugs.eclipse.org/bugs/show_bug.cgi?id=281374#c1
/** * @memberOf myNamespace */ Did not work for me. When I add this above myFunc1(), it does not show it in the outline, even if I close and open the file.
Interestingly, 4 of my 20 or so functions do show up in the outline, but there is no difference between the ones which work and the ones which do not except the ones which work all have this.xxx in them (but if I add this.dummy; to invisible functions it does not help)
This semi works: myNameSpace.prototype = {}; myNameSpace;
But then you cant call its functions thusly: myNameSpace.myFunc1();
回答4:
I'm working with eclipse/Kepler. Using the advice from above I managed to get the outline view. But proposals (Ctrl-space) didn't work. Some fn were visible, some not. No pattern to detect.
After reading http://usejsdoc.org/#JSDoc3_Tag_Dictionary I replaced all @memberOf by @memberof and now everything works as expected ('til the next problem arises ...)
来源:https://stackoverflow.com/questions/10208357/how-can-i-view-the-outline-in-eclipse-when-using-the-revealing-module-pattern