Node.js – process.throwDeprecation() 方法
node.jsserver side programmingprogramming
此方法指示当前 Node.js 项目中 --throw-deprecation 标志的值设置为 True 或 False。
process.throwDeprecation() 方法是可变的,因此弃用警告导致的错误可能会在运行时更改。
语法
process.throwDeprecation()
示例 1
创建一个名为"throwDeprecation.js"的文件,并复制以下代码。创建文件后,使用命令"node throwDeprecation.js"按照以下示例所示运行此代码
// process.throwDeprecation() 演示示例 // 导入 process 模块 const process = require('process'); // 打印 --throw-Deprecation 默认值 console.log(process.throwDeprecation);
输出 1
undefined
输出 2
true
示例 2
我们再举一个例子
// process.throwDeprecation() 演示示例 // 导入 process 模块 const process = require('process'); // 初始化 throwDeprecation 标志 process.throwDeprecation = false; // 打印 throwDeprecation console.log(process.throwDeprecation); // 初始化 throwDeprecation 标志 process.throwDeprecation = true; // 打印 throwDeprecation console.log(process.throwDeprecation);
输出 1
false true
输出 2
true true