在JSDoc中为内联匿名函数定义参数

Rea*_*lar 4 javascript annotations jsdoc phpstorm

如果我将函数定义为变量对象,那么PhpStorm将显示item参数的自动完成.

        /**
         * @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);
Run Code Online (Sandbox Code Playgroud)

如果我为_.each()函数的内联参数写相同的东西.然后它不起作用.

        _.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);
            }
        });
Run Code Online (Sandbox Code Playgroud)

Rea*_*lar 12

我找到了答案.这里是.

    _.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);
        }
    });
Run Code Online (Sandbox Code Playgroud)

  • 您在文档中的哪里找到了这个?我的编辑似乎不明白 (2认同)