Search code examples
javascriptnetbeansautocompletenetbeans-8

Is there a way to force NetBeans JavaScript Autocomplete?


I am developing some JavaScript to be used in a CMS I'm working on.

I have encapsulated my code like this:

(function(){
    var libraryName = {};
    ...code...
    window.libraryName = libraryName;
}())

Now when I add a subnamespace and try using it outside my declaration, the NetBeans (8.0.2) autocomplete function doesn't work. Like this:

(function(){
    var libraryName = {};
    libraryName.subSet = {
            showSomething: function(){}
    };
    window.libraryName = libraryName;
}())
libraryName.subSet.showSomething(); // This works
libraryName.subSet. // No current autocomplete even when pressing CTRL+space

I would like to know if there is some way to tell NetBeans how to autocomplete instead of it guessing.

Thanks


Solution

  • I tried another approach which worked for me.

    I copied my JavaScript file and removed the encapsulation. So I now have two files, the "real" one with the encapsulation and another "working" one that doesn't have the encapsulation. Now when I try using the autocomplete it works.

    The downside for this is that you create noise since there is a file that isn't meant for the web app and you have to update it every time you update the original file. But it makes coding easier with the magic of autocomplete. When you load html you just don't reference the "working" file.

    So, this would be my main.js file (in /js/main.js for instance)

    (function(){
    var libraryName = {};
    libraryName.subSet = {
            showSomething: function(){}
    };
    window.libraryName = libraryName;
    }())
    

    And a main.tmp.js file would be like this (in /tmp/main.tmp.js for instance)

    var libraryName = {};
    libraryName.subSet = {
            showSomething: function(){}
    };
    

    Now, when I do libraryName.subSet. it shows me the correct autocomplete with showSomething.