Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define parameters in JSDoc for inline anonymous functions

If I define the function as a variable object, then PhpStorm will show the auto-complete for the item parameter.

        /**
         * @param {Rules.FolderGroupItem} item
         **/
        var forEach = function(item) {
            if(item.type == 'label')
            {
                str += this.renderLabel(item.paramType);
            }
            if(item.type == 'input')
            {
                str += this.renderInput(item.paramType);
            }
        };
        _.each(items,forEach,this);

If I write the same thing as an inline parameter for the _.each() function. Then it doesn't work.

        _.each(items,forEach,
            /**
             * @param {Rules.FolderGroupItem} item
             **/
            function(item) 
        {
            if(item.type == 'label')
            {
                str += this.renderLabel(item.paramType);
            }
            if(item.type == 'input')
            {
                str += this.renderInput(item.paramType);
            }
        });
like image 461
Reactgular Avatar asked Dec 15 '22 11:12

Reactgular


1 Answers

I found the answer. Here it is.

    _.each(items,forEach,function(/*Rules.FolderGroupItem*/item) 
    {
        if(item.type == 'label')
        {
            str += this.renderLabel(item.paramType);
        }
        if(item.type == 'input')
        {
            str += this.renderInput(item.paramType);
        }
    });
like image 68
Reactgular Avatar answered Dec 26 '22 00:12

Reactgular