admin管理员组

文章数量:1410724

I need to use JSDoc to make sock, data variables known

var exec = {
    /**
     * @param {Number} sock
     * @param {String} data
     */
    1: (sock, data) => {
        console.log("GG");
    },
    2: (sock, data) => {

    },
    3: (sock, data) => {

    }
};

let's say sock is Number, and data is String.

/**
 * @param {Number} sock
 * @param {String} data
 */

I need to set the JSDoc one time only, for the whole object.

I need to use JSDoc to make sock, data variables known

var exec = {
    /**
     * @param {Number} sock
     * @param {String} data
     */
    1: (sock, data) => {
        console.log("GG");
    },
    2: (sock, data) => {

    },
    3: (sock, data) => {

    }
};

let's say sock is Number, and data is String.

/**
 * @param {Number} sock
 * @param {String} data
 */

I need to set the JSDoc one time only, for the whole object.

Share Improve this question edited Apr 24, 2021 at 13:52 CorrM asked Apr 9, 2019 at 18:54 CorrMCorrM 5276 silver badges22 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7
/**
 * @type {Object.<number, function(Object, Object):void>}
 */
var exec = {
    1: (sock, data) => {
        console.log("GG");
    },
    2: (sock, data) => {

    },
    3: (sock, data) => {

    }
};

This defines an object with numbers as keys and functions as values which takes two params of type Object.

The Syntax piles from

Object.<[keyType, valueType]>

and

function(param1Type, param2Type, ...):returnType

本文标签: javascriptJSDoc for Lambda function in objectStack Overflow