📜  Node.js process.throwDeprecation 属性

📅  最后修改于: 2022-05-13 01:56:42.999000             🧑  作者: Mango

Node.js process.throwDeprecation 属性

process.throwDeprecation 属性是 process 模块的内置应用程序编程接口,用于指示是否在当前 Node.js 进程上设置了 --throw-deprecation 标志。 process.throwDeprecation 是可变的,因此弃用警告是否导致错误可能会在运行时更改。

句法:

process.throwDeprecation

返回值:该属性表示是否在当前 Node.js 进程上设置了 --throw-deprecation 标志。

下面的示例说明了在 Node.js 中process.throwDeprecation 属性的使用:

示例 1:

Javascript
// Node.js program to demonstrate the
// process.throwDeprecation Property
  
// Include process module
const process = require('process');
  
// Printing process.throwDeprecation
// property value
console.log(process.throwDeprecation);


Javascript
// Node.js program to demonstrate the
// process.throwDeprecation Property
  
// Include process module
const process = require('process');
  
// Instance Properties
process.throwDeprecation = false;
  
// Printing process.throwDeprecation
// property value
console.log(process.throwDeprecation);
  
// Instance Properties
process.throwDeprecation = true;
  
// Printing process.throwDeprecation
// property value
console.log(process.throwDeprecation);


运行命令: node –throw-deprecation hello.js

输出 1:

true

运行命令: node hello.js

输出 2:

undefined

示例 2:

Javascript

// Node.js program to demonstrate the
// process.throwDeprecation Property
  
// Include process module
const process = require('process');
  
// Instance Properties
process.throwDeprecation = false;
  
// Printing process.throwDeprecation
// property value
console.log(process.throwDeprecation);
  
// Instance Properties
process.throwDeprecation = true;
  
// Printing process.throwDeprecation
// property value
console.log(process.throwDeprecation);

运行命令: node –throw-deprecation hello.js

输出 1:

true
true

运行命令: node hello.js

输出 2:

false
true

参考: https://nodejs.org/api/process.html#process_process_throwdeprecation