Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JsDoc: Remove "static" tag from property

I have graph constructor written in JavaScript. The documentation is a bit borked. Below is the part of my code and the documentation which does not work as I want:

function Graph() {
    ....
    var nodes = [];
    Object.defineProperties(this, {
        /**
         * An array of all node handles in the graph
         *
         * @return {Array}
         */
        nodes: {
            get: function() {
                var ids = [];
                for (var id in nodes) {
                    ids.push(id);
                }
                return ids;
            }
        }
    });
    ....
}

Basically, what I'm trying to do is to make sure the graph can't be manipulated using other means than the methods provided by giving a copy of the node list, not the actual node list.

This works well, but in the JsDoc, it is defined as static:

<static>    Graph.nodes
            An array of all node handles in the graph

Now, this property is not static. It is individual for all instances of graphs. My guess is that JsDoc recognizes the definition of the nodes property to be inside Object.defineProperties(), and claims that all declarations inside here are static.

Is there a way to tell JsDoc that this property is in fact not static? I could only find the tag @static, which does the exact opposite.

like image 891
Suppen Avatar asked Jan 08 '23 19:01

Suppen


1 Answers

There is @instance, see the documentation

// Edit: Working example

/**
 * @constructor
 */
function Graph() {
    var nodes = [];
    Object.defineProperties(this, {
        /**
         * An array of all node handles in the graph
         * @return {Array}
         * @memberof Graph
         * @instance
         */
        nodes: {
            get: function() {
                var ids = [];
                for (var id in nodes) {
                    ids.push(id);
                }
                return ids;
            }
        }
    });
}
like image 197
Valentin Klinghammer Avatar answered Jan 18 '23 01:01

Valentin Klinghammer