Search code examples
javascripteclipseclassscopecode-completion

JavaScript class definition local scope enable global code completion with tern


We use this way to define classes in our js code:

  ( function( $, wb ) {
        "use strict";

        /**
        * @class wb.QueryServiceEditor
        * @constructor
        */
        var SELF = wb.QueryServiceEditor = function QueryServiceEditor(
        ) {
        };

        SELF.prototype.fromTextArea = function( selector ){
        };

    }( jQuery, wb ) );

The problem I have with this approach is that the code completion I use (eclipse + tern) is not working well with this when using this class QueryServiceEditor from a different scope.

How could we improve our code to make code completion possible everywhere?


Solution

  • The important thing when you work with ternjs is that you must declare your variable. Perhaps you have not declared your wb variable?

    I have tried with tern.java 1.1.0-SNAPSHOT and it seems it works, here a screenshot with completion for fromTextArea method:

    enter image description here