2010年1月27日水曜日

debug() for js

このエントリーをブックマークに追加 このエントリーを含むはてなブックマーク
(function($){
  function debug(){
    if (window['console']){
      console.log.apply(null, arguments);
    };
  };
}(jQuery);
いくつかpointをば:
  • functionで囲う。これはname spaceの汚染防止
  • window['console']のガード:firebugがあがっていないときはlogしない。
  • apply~はdebugに可変長引数をパススルーするトリック。

0 件のコメント: