LoginSignup
1
2

More than 3 years have passed since last update.

[Node.js 12] delete console.log

Posted at

概要

Node.js 12のどのタイミングからか動きが変わったのでメモです。

やってたこと


> process.versions.node
'10.16.3'
> console.log('hoge')
hoge
undefined
> console.log = () => '無効化!'
[Function]
> console.log('hoge')
'無効化!'
> delete console.log
true
> console.log('hoge')
hoge
undefined

console.log() => {} で上書きして何もしない関数にする。
(今回の例では () => '無効化!' で上書きしたけれども)

従来の console.log に戻したい時には delete console.log して上書き分を消す、というようなことをしていました。

参考: https://it7c.hatenadiary.org/entry/20140415/1397494773

Node.js 12.6.0

> process.versions.node
'12.6.0'
> console.log('hoge')
hoge
undefined
> console.log = () => '無効化!'
[Function]
> console.log('hoge')
'無効化!'
> delete console.log
true
> console.log('hoge')
Thrown:
TypeError: console.log is not a function
> console.log
undefined

deleteしたら全部消えた?

まとめ

console.logの無効化の良いやり方があったら知りたい。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2