【问题标题】:Array.<number> or Array<number>?Array.<number> 还是 Array<number>?
【发布时间】:2019-03-14 05:27:42
【问题描述】:

数组表示法的正确 JSDoc 格式是什么?

Array.&lt;number&gt;Array&lt;number&gt;?

我见过两者可以互换使用,不知道有没有区别。

关于Promise&lt;number&gt;,我也可以使用Promise.&lt;number&gt;吗?

【问题讨论】:

标签: javascript jsdoc jsdoc3


【解决方案1】:

闭包编译器使用Array&lt;number&gt;。可能其他风格的 JSDocs 更喜欢 Array.&lt;number&gt;,但我没有使用过它们。

例如:

/**
 * Sorts an array of objects by the specified object key and compare
 * function. If no compare function is provided, the key values are
 * compared in ascending order using <code>goog.array.defaultCompare</code>.
 * This won't work for keys that get renamed by the compiler. So use
 * {'foo': 1, 'bar': 2} rather than {foo: 1, bar: 2}.
 * @param {Array<Object>} arr An array of objects to sort.
 * @param {string} key The object key to sort by.
 * @param {Function=} opt_compareFn The function to use to compare key
 *     values.
 */
goog.array.sortObjectsByKey = function(arr, key, opt_compareFn) {
  goog.array.sortByKey(arr, function(obj) { return obj[key]; }, opt_compareFn);
};

通过 - https://github.com/google/closure-library/blob/master/closure/goog/array/array.js#L1194

【讨论】:

    猜你喜欢
    • 2020-04-19
    • 1970-01-01
    • 2022-12-02
    • 2017-04-01
    • 2021-05-31
    • 2016-05-02
    • 1970-01-01
    • 1970-01-01
    • 2021-01-04
    相关资源
    最近更新 更多