Help us understand the problem. What is going on with this article?

[Node.js 12] delete console.log

概要

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の無効化の良いやり方があったら知りたい。

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away