Node.js – util.types.isBoxedPrimitive() 方法
该UTIL。types.isBoxedPrimitive()方法检查传递的值是否是内置的Primitive对象。如果满足上述条件,则返回True,否则返回False。原始对象包括newBoolean()、newString()或Object(Symbol())。
语法
util.types.isBoxedPrimitive(value)
参数
value- 此输入值接受所需参数的输入并检查它是否是Float32-Array实例。
它根据传递的输入值返回True或False。
示例1
创建一个名为“isBoxedPrimitive.js”的文件并复制以下代码片段。创建文件后,使用命令“nodeisBoxedPrimitive.js”运行此代码。
//util.types.isBoxedPrimitive()演示示例 //导入util模块 const util = require('util'); //将布尔值作为变量传递 console.log("1." + util.types.isBoxedPrimitive(false)); //将布尔值作为原始对象传递 console.log("2." + util.types.isBoxedPrimitive(new Boolean(false))); //将“foo”作为值传递 console.log("3." + util.types.isBoxedPrimitive(Symbol('foo'))); //将“foo”作为对象传递 console.log("4." + util.types.isBoxedPrimitive(Object(Symbol('foo'))));输出结果
C:\home\node>> node isBoxedPrimitive.js 1.false 2.true 3.false 4.true
示例2
//util.types.isFloat32Array()演示示例 //导入util模块 const util = require('util'); var float32 = new Float32Array(2); float32[0] = 21; var stringObj = new String('Welcome to nhooo.com') var bigInt = Object(BigInt(5)); //传递float32对象作为输入 console.log("1." + util.types.isBoxedPrimitive(float32)); //传递字符串对象 console.log("2." + util.types.isBoxedPrimitive(stringObj)); //传递一个BigInt对象 console.log("3." + util.types.isBoxedPrimitive(bigInt));输出结果
C:\home\node>> node isBoxedPrimitive.js 1.false 2.true 3.true