Search code examples
javascriptnetbeanscode-completionjsdoc

Document methods defined using Simple JavaScript Inheritance


I'm defining classes using John Resig's Simple JavaScript Inhertance and documenting them with JSDoc's @lends and @constructs annotations, but NetBeans doesn't provide code-completion. This works with modules I've defined using namespace because I'm referencing them directly. Here's an example of a simple class:

MyClass = Class.extend(
    /** @lends MyClass.prototype */
    {
        /** @constructs */
        init: function () {
            console.log('init');
        },

        foo: function () {
            console.log('foo');
        }
    }
);

var c = new MyClass();
c.  <-- ctrl-space only shows built-in methods like hasOwnProperty() and toString()

Does anyone know a way to document these classes so code-completion is available in NetBeans?


Solution

  • NetBeans does not support @lends, @constructs, @memborOf or similar tags still. They are set for 7.4 and 8.0 but I don't believe they will be implemented soon since they are reported from 7.0 or so. The second of two workarounds will work with Class.extend() by first assigning the (previously) anonymous object containing the methods to the class.

    Prototype

    /** @class */
    var Canine;
    Canine = function() {};
    Canine.prototype = props;
    
    /** @type Canine */ var canine = new Canine();
    

    Anonymous Object

    /** @class */
    var Feline = {
        purr: function() { console.log('meow'); },
        fall: function() { console.log('landed on feet'); }
    };
    Feline = create(Feline);
    
    /** @type Feline */ var feline = new Feline();
    

    Note: This works even without the @type comment in NetBeans 7.4 patch 1.