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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。