为了调试方便,我们有时候会这样写log()

 1 /** @define {boolean} */
2 var DEBUG = true;
3
4 function log() {
5 if (DEBUG) {
6 console.log.apply(this, arguments);
7 }
8 }
9
10 function foo(bar) {
11 log('bar is %s.', bar);
12 }

发布代码的时候只要在Closure Compiler的参数里设置 DEBUG=false 就不用手动删除每一条log()调用了。

但是上面的代码在webkit里面会报错:

Uncaught TypeError: Illegal invocation

其实需要这么写:

console.log.apply(console, arguments);



相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-30
  • 2022-02-05
  • 2022-12-23
  • 2021-07-14
  • 2022-01-23
猜你喜欢
  • 2022-03-08
  • 2022-12-23
  • 2021-07-15
  • 2021-11-01
  • 2022-12-23
相关资源
相似解决方案