0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

console.log を print に置き換える

Last updated at Posted at 2022-07-23

console.log を print に置き換える

console.log と入力するのが面倒なので print にしたいという話です
いつもやり方忘れるのでメモしておきたい

追記: print は印刷ダイアログを出す命令になっているので putlog とか別の名前にしたほうが良さそうですね

function print() {
    console.log.apply(console, arguments);
}

print("hoge", "piyo", 1234);

apply と call による関数呼び出し

[関数].apply(thisポインタ, [引数1, 引数2, 引数3, ...]);
[関数].call(thisポインタ, 引数1, 引数2, 引数3, ...);
こんなイメージです。

// 使用例
var o = {
    fn: function() {/* なんらかの処理 */}
};

o.fn.apply(o, [1, 2, 3]);
o.fn.call(o, 1, 2, 3);

以上です

0
0
2

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?