阵列。 或数组 ?

问题描述 投票:1回答:1

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

Array.<number>Array<number>

我已经看到这两个可以互换使用,不知道是否存在差异。

另外,当谈到Promise<number>时,我还可以使用Promise.<number>吗?

javascript jsdoc jsdoc3
1个回答
2
投票

Closure编译器使用Array<number>。可能其他风格的JSDocs更喜欢Array.<number>,但我没有使用它们。

例如:

/**
 * 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);
};

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

© www.soinside.com 2019 - 2024. All rights reserved.