5

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.

0

1 Answer 1

9

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;
            }
        }
    });
}
3
  • I have updated my answer and hope, that answers question more thoroughly. Version 3.3.0 of JSDoc produces the intended output. Feb 28, 2015 at 13:37
  • Still did not work, but may very well be because of outdated version. I have 2.4.0. Will update and test again
    – Suppen
    Feb 28, 2015 at 15:09
  • Updating it did the trick! In addition to fixing it, the generated documentation looks much better! Thanks!
    – Suppen
    Feb 28, 2015 at 15:17

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.