JavaScript typedArray.@@species用法示例

2021年5月3日18:13:03 发表评论 100 次浏览

typedArray.@@species是JavaScript中的内置属性, 用于返回给定typedArray的构造函数。

typedArray具有许多类型, 例如-

  • Int8Array
  • Uint8Array
  • Uint8ClampedArray
  • Int16Array
  • Uint16Array
  • Int32Array
  • Uint32Array
  • Float32Array
  • Float64Array

语法如下:

typedArray[Symbol.species]

参数:

它不接受任何参数, 因为它是属性而不是函数。

返回值:

它返回给定typedArray的构造函数。

JavaScript代码显示此属性的工作方式:

<script>
  
     //Calling species property on different typedArray
     a = Int8Array[Symbol.species];
     b = Uint8Array[Symbol.species];
     c = Uint8ClampedArray[Symbol.species];
     d = Int16Array[Symbol.species];
     e = Uint16Array[Symbol.species];
     f = Int32Array[Symbol.species];
     g = Uint32Array[Symbol.species];
     h = Float32Array[Symbol.species];
     i = Float64Array[Symbol.species];
  
     //Printing the constructor of the given typedArray
     document.write(a + "<br>" );
     document.write(b + "<br>" );
     document.write(c + "<br>" );
     document.write(d + "<br>" );
     document.write(e + "<br>" );
     document.write(f + "<br>" );
     document.write(g + "<br>" );
     document.write(h + "<br>" );
     document.write(i);
  
</script>

输出如下:

function Int8Array() { [native code] }
function Uint8Array() { [native code] }
function Uint8ClampedArray() { [native code] }
function Int16Array() { [native code] }
function Uint16Array() { [native code] }
function Int32Array() { [native code] }
function Uint32Array() { [native code] }
function Float32Array() { [native code] }
function Float64Array() { [native code] }

一盏木

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: