util.types.isExternal() 方法是 util 模块的内置应用程序编程接口,用于检查该值是否是 node.js 中的本机外部值。
用法:
util.types.isExternal( value )
参数:该方法接受上面提到和下面描述的单个参数。
- value:它是任何数据类型的必需参数。
返回值:这将返回一个布尔值,如果该值是本机外部值,则为 TRUE,否则为 FALSE。
下面的例子说明了 util.types.isExternal() 方法在 Node.js 中的使用:
范例1:
Javascript
// Node.js program to demonstrate the
// util.types.isExternal() Method
// Allocating util module
const util = require('util');
// Value to be passed as parameter
// of util.types.isExternal() method
var v1 = new Date();
const { JSStream } = process.binding('js_stream');
const external = (new JSStream())._externalStream;
// Printing the returned value from
// util.types.isExternal() method
console.log(util.types.isExternal(v1));
console.log(util.types.isExternal(external));
console.log(util.types.isExternal(0));
console.log(util.types.isExternal(new String('foo')));
输出:
false true false false
范例2:
Javascript
// Node.js program to demonstrate the
// util.types.isExternal() Method
// Allocating util module
const util = require('util');
// Value to be passed as parameter
// of util.types.isExternal() method
var v1 = new Date();
const { JSStream } = process.binding('js_stream');
const ext = (new JSStream())._externalStream;
var str = new String('Geeks')
// Calling
// util.types.isExternal() method
if (util.types.isExternal(v1))
console.log("It is a native External value.");
else
console.log("It is not a native External value.");
if (util.types.isExternal(ext))
console.log("It is a native External value.");
else
console.log("It is not a native External value.");
if (util.types.isExternal(0))
console.log("It is a native External value.");
else
console.log("It is not a native External value.");
if (util.types.isExternal(str))
console.log("It is a native External value.");
else
console.log("It is not a native External value.");
输出:
It is not a native External value. It is a native External value. It is not a native External value. It is not a native External value.
参考: https://nodejs.org/api/util.html#util_util_types_isexternal_value
相关用法
- Node.js console.timeLog()用法及代码示例
- Node.js x509.toLegacyObject()用法及代码示例
- Node.js fs.fsyncSync()用法及代码示例
- Node.js process.nextTick()用法及代码示例
- Node.js GM charcoal()用法及代码示例
- Node.js GM blur()用法及代码示例
- Node.js GM sharpen()用法及代码示例
注:本文由纯净天空筛选整理自SHUBHAMSINGH10大神的英文原创作品 Node.js util.types.isExternal() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。