javascriptnetbeansgo-to-definition

How to use "Go to Declaration" with NetBeans and javascript?


I know we can use Ctrl+Click or Ctrl+B in NetBeans, but it doesn’t work for me when I’m writing javascript files.

And I’m not the only one (sadly that question has no reply).

I can see the functions on the Navigator, but I can’t use “Go to declaration”.

I’m declaring my functions this way:

function anyName(params...) { ... }

I tried changing to this style:

var anyName = function (params...) { ... }

But that didn’t work either.

I’m using Netbeans 6.9.1.

More info:

  1. NetBeans supports “Go to declaration” in javascript.
  2. As I said, the function is recognized because I can see it in the Navigator.
  3. I can use Ctrl+O and then search for my function, and NetBeans can find it when I do that. I’m using this right now as a poor replacement for “Go to declaration”.
  4. I’ve noticed that I don’t have code completion either. Following the above example, if I write “an” (Ctrl+Space) I can see a lot of functions and methods but I can’t find my function (anyName).

I think I’m doing something really wrong, but I don’t know what.


Solution

  • The problem seems to be in defining everything as “global”. If you work in your own namespace — that is, create a global object and define everything there — then Netbeans can understand better where your code is and can also give you type hints.