多才多艺的console

原文链接:http://www.thecssninja.com/javascript/console

记下一部分精华:

console.log函数可以写一些有用的信息到控制台,但是很少有人用到,console还包含大概其他20多个函数可以用,提供了多种多样的功能。

1.log函数可以用多个参数

var foo = {baz: "tubular", goo: "rad"}, bar = "baz";
console.log("string",1,foo.goo,bar,foo.baz); // string 1 rad baz tubular

2.log函数可以格式化输出

var foo = {baz: "tubular", goo: "rad"}, bar = "baz";
console.log(
     "%s theory is %d %s concept. I can only describe it as %s and %s",
      "string", 1, foo.goo, bar, foo.baz 
);
// string theory is 1 rad concept. I can only describe it as baz and tubular

3.多种信息

console.info,console.error,console.warn

4.记录dom

console.dir(document.documentElement);
console.dirxml(document.documentElement);

5.分组

console.group(), console.groupCollapsed() 和console.groupEnd().可以折叠一个组的显示。

6.计时

console.time("Execution time took");
// Some code to execute
console.timeEnd("Execution time took");

7.profiling

console.profile();
// Some code to execute
console.profileEnd();

8.断言

var a = 1, b = "1";
console.assert(a === b, "A doesn't equal B");

  

 9.trace

打印stack trance,(还不知道咋用)

 

 

posted @ 2012-08-30 17:01  1gehunzi  阅读(122)  评论(0编辑  收藏  举报