Created
September 19, 2020 22:22
-
-
Save shizuka-na-kazushi/734d00253b73647648ba530b8bae35bf to your computer and use it in GitHub Desktop.
console.logを Proxy オブジェクトで書き換える
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// console.logを置き換えて、 | |
// 出力の先頭に '(xxxxxxx)'のように現在の時間を表示する | |
console.log = new Proxy(console.log, { | |
apply: function(target, thisArg, argList) { | |
var n = Date.now(); | |
argList[0] = '(' + n + ') ' + argList[0]; | |
return target.apply(thisArg, argList); | |
} | |
}) | |
var a = ['hello', ', ', 'world', '!']; | |
a.forEach((str) => { | |
console.log(str); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment