Skip to content

Instantly share code, notes, and snippets.

@shizuka-na-kazushi
Created September 19, 2020 22:22
Show Gist options
  • Save shizuka-na-kazushi/734d00253b73647648ba530b8bae35bf to your computer and use it in GitHub Desktop.
Save shizuka-na-kazushi/734d00253b73647648ba530b8bae35bf to your computer and use it in GitHub Desktop.
console.logを Proxy オブジェクトで書き換える
// 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