util模块的util.types.isSharedArrayBuffer()方法主要旨在满足Node.js自己的内部API的需求。它用于检查方法中传递的实例是否为内置 SharedArrayBuffer实例。
用法:
util.types.isSharedArrayBuffer( value )
参数:此方法接受单个参数值,该参数值包含任何值,即任何模块的实例。
返回值:此方法返回一个布尔值,即,如果传递的值是SharedArrayBuffer的实例,则为true,否则返回false。
以下示例说明了Node.js中util.types.isSharedArrayBuffer()方法的使用:
范例1:
// Node.js program to demonstrate the
// util.types.isSharedArrayBuffer() method
// It includes util module
const util = require('util');
// Return true as passed instance
// is of SharedArrayBuffer
console.log(util.types.isSharedArrayBuffer(
new SharedArrayBuffer()));
// Return false as passed instance
// is of Int32Array
console.log(util.types.isSharedArrayBuffer(
new Int32Array()));
// Return false as the passed instance is
// of ArrayBuffer, not SharedArrayBuffer
console.log(util.types.isSharedArrayBuffer(
new ArrayBuffer()));
输出:
true false false
范例2:
// Node.js program to demonstrate the
// util.types.isSharedArrayBuffer() method
// It includes util module
const util = require('util');
// making an instance of SharedArrayBuffer
// of size 1024
var sab = new SharedArrayBuffer(1024);
// Return true as passed instance is
// of SharedArrayBuffer
console.log(util.types.isSharedArrayBuffer(sab));
// Return true as slice method return new
// instance of sharedArrayBuffer
console.log(util.types.isSharedArrayBuffer(
sab.slice(100, 199)));
输出:
true true
参考: https://nodejs.org/api/util.html#util_util_types_issharedarraybuffer_value
相关用法
注:本文由纯净天空筛选整理自akshajjuneja9大神的英文原创作品 Node.js | util.types.isSharedArrayBuffer() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。