當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Node.js util.types.isExternal()用法及代碼示例

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




相關用法


注:本文由純淨天空篩選整理自SHUBHAMSINGH10大神的英文原創作品 Node.js util.types.isExternal() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。