Node.js – process.throwDeprecation() 方法


此方法指示 **--throw-deprecation** 標誌值在當前 Node.js 專案中設定為 true 或 false。

process.throwDeprecation() 方法是可變的,因此棄用警告導致的錯誤可能會在執行時被更改。

語法

process.throwDeprecation( )

示例1

建立一個名為"throwDeprecation.js"的檔案,並複製以下程式碼。建立檔案後,使用"node throwDeprecation.js"命令執行此程式碼,如下例所示

// process.throwDeprecation() Demo Example

// Importing the process module
const process = require('process');

// Printing the --throw-Deprecation default value
console.log(process.throwDeprecation);

輸出 1

undefined

輸出 2

true

示例 2

我們來看另一個示例

// process.throwDeprecation() Demo Example

// Importing the process module
const process = require('process');

// Initializing the throwDeprecation flag
process.throwDeprecation = false;

// Printing throwDeprecation
console.log(process.throwDeprecation);

// Initializing the throwDeprecation flag
process.throwDeprecation = true;

// Printing throwDeprecation
console.log(process.throwDeprecation);

輸出 1

false
true

輸出 2

true
true

更新於: 2021 年 11 月 24 日

50 次瀏覽

啟動您的 事業

完成課程並獲得認證

開始
廣告
© . All rights reserved.