interrupt console.log

2015/03/04 社内勉強会

log = console.log

log("hogehoge")

省略したい

_人人人人人人人人人人人人人人人人人人人人_
> Uncaught TypeError: Illegal invocation <
 ̄Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y ̄

console.logには単独で動く

functionが入ってるわけじゃない

log = console.log

log.apply(console, ["hogehoge"])

こうする

log = console.log.bind(console)

log("hogehoge")

もしくはこうする

var original = console.log;

console.log = function() {
  var args = [].slice.apply(arguments);

  original.apply(console, args);

  args.forEach(function(arg) {
    var log = document.createTextNode(arg + '\n');
    document.body.appendChild(log);
  });
}

console.log("hoge", "fuga");

割り込むやつ

https://github.com/nakajmg/DemoLogger.js

fin

interrupt console.log

By nakajmg

interrupt console.log

Interrupt console.log. https://github.com/nakajmg/DemoLogger.js

  • 2,537