【问题标题】:why "Optional parameter name %s must be prefixed with opt_." in gjslint --strict mode?为什么“可选参数名称 %s 必须以 opt_ 为前缀。”在 gjslint --strict 模式下?
【发布时间】:2013-04-11 03:48:40
【问题描述】:

我在一个特定的 javascript 文件中得到以下信息

Line 23, E:0233: Optional parameter name category must be prefixed with opt_.
Line 649, E:0233: Optional parameter name animate must be prefixed with opt_.
Line 697, E:0233: Optional parameter name aggregate must be prefixed with opt_.
Line 763, E:0233: Optional parameter name animate must be prefixed with opt_.
Line 796, E:0233: Optional parameter name animate must be prefixed with opt_.

第一个代码是:

/** @constructor
 *
 *  @param {Object} data an entity or item.
 *  @param {Object} parent a viewObj, or at the root level, a viewstate.
 *  @param {Array.<number>} position an (x$, y$) pair.
 *  @param {string=} category The category to give the item. This forms an
*                             inconsistent mess around where category is stored.
 */
function ViewObj(data, parent, position, category) {

错误代码的意义何在? “类别”不是可选的!

【问题讨论】:

    标签: javascript gjslint


    【解决方案1】:

    类型中的= 后缀意味着它是可选的。如果category 参数不是可选的,那么您应该将其类型更改为string

    此错误的目的是确保清楚哪些参数是可选的(根据gjslint 使用的样式指南,不仅它们的类型反映了它,而且它们的名称也反映了它),并且不是。

    【讨论】:

    • 啊,嗯,嗯。是时候脸红了。谢谢。
    猜你喜欢
    • 2020-01-09
    • 2021-11-23
    • 1970-01-01
    • 1970-01-01
    • 2020-05-23
    • 2014-02-19
    • 1970-01-01
    • 2020-08-12
    • 1970-01-01
    相关资源
    最近更新 更多