esdoc / esdoc

ESDoc - Good Documentation for JavaScript
https://esdoc.org
MIT License
2.74k stars 204 forks source link

Multiple constructors #466

Open robertmain opened 7 years ago

robertmain commented 7 years ago

Make sure these boxes are checked before submitting your issue - thank you! (If your issue is neither a both bug nor a request, please write in a free style)

Short summary of your issue

Whilst I'm aware of the fact that none of the current ECMAScript standards support multiple constructors, it is possible to (sort of) support this functionality and it would be cool if ESDoc had some capability for me to document multiple ways of constructing my class

Input data for reproducing

Configuration

{
    "source":"./src",
    "destination":"./docs",
    "includes":[
        "\\.js$"
    ],
    "excludes":[
        "\\uint32.js$"
    ],
    "plugins":[
        {
            "name":"esdoc-standard-plugin",
            "option":{
                "lint":{
                    "enable":true
                },
                "coverage":{
                    "enable":true
                },
                "accessor":{
                    "access":[
                        "public",
                        "protected",
                        "private"
                    ],
                    "autoPrivate":true
                },
                "undocumentIdentifier":{
                    "enable":true
                },
                "unexportedIdentifier":{
                    "enable":false
                },
                "typeInference":{
                    "enable":true
                }
            }
        },
        {
            "name": "esdoc-node"
        }
    ]
}

Code

/**
 * Construct a Line using two {@link Point} objects
 * .
 * @param {Point} start An instance of {@link Point} containing X and Y co-ordinates
 * @param {Point} end   An instance of {@link Point} containing X and Y co-ordinates
 * @memberof Line
 */
/**
 * Construct a Line using 4 {@link number}s
 * @param {number} startX Starting position on the X axis
 * @param {number} startY Starting position on the Y axis
 * @param {number} endX   Ending position on the X axis
 * @param {number} endY   Ending position on the Y acis
 * @memberof Line
 */
constructor (){
    if (arguments.length === 4) {
        this.start = {};
        this.end   = {};
        [this.start.x, this.start.y, this.end.x, this.end.y] = arguments;
    } else if(arguments.length === 2) {
        [this.start, this.end] = arguments;
    } else {
        throw Error('Please pass either two Point objects, or 4 integers to the constructor');
    }
}

Output data

Log

n/a

Screen shot of documentation

// attach a image into here

Exception output (if possible)

Log

// write into here

Screen shot of documentation

// attach a image into here

Your environment

MattMcFarland commented 7 years ago

Interesting proposal - while I personally disagree with this because javascript really doesnt support it and you're using a workaround - I dont see why esdoc cant really facilitate what your asking for, so this seems like an interesting feature to add.

robertmain commented 7 years ago

Thanks. Whilst I'm aware that TypeScriipt is not Java(which does support multiple constructors). It would be handy to be able to document the ability to construct an object in multiple ways as you said...

MattMcFarland commented 7 years ago

On second thought, I think we could make this a plugin.

robertmain commented 6 years ago

Forgot to say. The documentation that esdoc produces actually says "Public Constructors" which kind of implies that there may be more than one...hence my creation of this issue :)