toStrictArray

源码

https://github.com/ddzy/ts-utility-plugins/tree/master/src/ddzy/utility/array/toStrictArray

说明

将给定的类数组转化为严格的数组(非原地)

用法

index.ts
const p1 = utilityArray.toStrictArray({ length: 0 });
const p2 = utilityArray.toStrictArray<string | number>({
0: 'ddzy',
1: 20,
length: 2,
});
const p3 = utilityArray.toStrictArray<HTMLElement>(
document.querySelectorAll('div'),
);
const p4 = utilityArray.toStrictArray(
[1, 2, 3, 4]
);
console.log(p1); // []
console.log(p2); // ['ddzy', 20]
console.log(p3); // [HTMLDivElement, ...]
console.log(p4); // [1, 2, 3, 4]

坑点

  • ts中使用call的方式 ---> xxx.call(() => origin)