util模塊的util.types.isInt32Array()方法主要旨在滿足Node.js自己的內部API的需求。它用於檢查方法中傳遞的實例是否為內置 Int32Array實例。
用法:
util.types.isInt32Array( value )
參數:此方法接受單個參數值,該參數值包含任何值,即任何模塊的實例。
返回值:此方法返回一個布爾值,即,如果傳遞的值是Int32Array的實例,則返回true,否則返回false。
以下示例說明了Node.js中util.types.isInt32Array()方法的使用:
範例1:
// Node.js program to demonstrate the
// util.types.isInt32Array() method
// It includes util module
const util = require('util');
// Return false as passed instance is of map
console.log(util.types.isInt32Array(new Map()));
// Return true as passed instance is of Int32Array
console.log(util.types.isInt32Array(new Int32Array()));
輸出:
false true
範例2:
// Node.js program to demonstrate the
// util.types.isInt32Array() method
// It includes util module
const util = require('util');
// Making an instance of Int32Array
// of size 2
var array1 = new Int32Array(2);
// Intializing the zeroth element
array1[0] = 42;
// Returns true as passed instance is of Int32Array
console.log(util.types.isInt32Array(array1));
// Making an instance of Int32Array
var array2 = new Int32Array([21, 31]);
// Returns true as passed instance is of Int32Array
console.log(util.types.isInt32Array(array2));
// Making an instance of Int32Array
var array3 = new Int32Array([21, 31]);
// Making another instance of Int32Array by
// passing an instance of Int32Array
var array4 = new Int32Array(array3);
// Returns true as passed instance is of Int32Array
console.log(util.types.isInt32Array(array4));
// Making an instance of Int16Array of size 2
var array5 = new Int16Array(2);
// Intializing the zeroth element
array5[0] = 10;
// Returns false as passed instance is of Int16Array
console.log(util.types.isInt32Array(array5));
輸出:
true true true false
參考: https://nodejs.org/api/util.html#util_util_types_isint32array_value
相關用法
注:本文由純淨天空篩選整理自akshajjuneja9大神的英文原創作品 Node.js | util.types.isInt32Array() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。