`
bee1314
  • 浏览: 163553 次
  • 性别: Icon_minigender_1
  • 来自: 安徽
社区版块
存档分类
最新评论

酸爽的console.log

阅读更多

在前端的开发中,console.log那是开发必备啊,简直直观。通过写小函数,组合大功能。更容易测试。但是在打版本时,就要删除console.log,打完版本进入开发状态又要添加,真不够爽。重复劳动太多。所以可以做些简单地封装,方便开发和上线。

/**
 * log.js hufeng
 * The safe wrapper for `console.xxx` functions
 *  log("message") ==> console.log("message")
 *  log("message", "warn") ==> console.warn("message")
 */

//cache current location hash, when the module loading
//only fetch hash one time.
var isDebug = parent.window.location.hash === '#debug';

module.exports = function() {	
  window.console &&
  // Do NOT print `log(msg)` in non-debug mode
  isDebug &&
  // Call native method of console
  // if not pass 'console' as first argument, 
  // chrome error!
  console.log.apply(console, arguments);
}

 

在使用console.log.apply调用的时候,上下文如果不传console,在chrome中会报错,囧。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics