Node.js – process.throwDeprecation() 方法

该方法表示当前项目中--throw-deprecation设置为 True 或 False的标志值Node.js。

该方法是可变的,因此可能会在运行时更改导致错误的弃用警告。process.throwDeprecation()

语法

process.throwDeprecation( )

示例 1

创建一个名为“ throwDeprecation.js ”的文件并复制以下代码。创建文件后,使用命令“ node throwDeprecation.js ”运行此代码,如下例所示

// process.throwDeprecation() 演示示例

// 导入流程模块
const process = require('process');

// 打印 --throw-Deprecation 默认值
console.log(process.throwDeprecation);

输出 1

undefined

输出 2

true

示例 2

让我们再举一个例子

// process.throwDeprecation() 演示示例

// 导入流程模块
const process = require('process');

// 初始化 throwDeprecation 标志
process.throwDeprecation = false;

// 打印抛出弃用
console.log(process.throwDeprecation);

// 初始化 throwDeprecation 标志
process.throwDeprecation = true;

// 打印抛出弃用
console.log(process.throwDeprecation);

输出 1

false
true

输出 2

true
true