ç°¡åãªã¡ã¢ïŒãããã°ã³ãŒãã䜿çšãããšãããã©ãŒãã³ã¹ã«æªåœ±é¿ãäžããå¯èœæ§ããããŸãã 補åçããåé€ããŸãã
åãªãã¡ãã»ãŒãžä»¥äžã®ãã®
ããŸãç¥ãããŠããªãã³ã³ãœãŒã«ã¡ãœããã«é£ã³èŸŒãåã«ãconsole.logæ©èœã詳现ã«æ€èšããŠãã ããã ããšãã°ãä»»æã®æ°ã®åŒæ°ãæž¡ãæ©èœïŒ
var foo = {baz: "tubular", goo: "rad"}, bar = "baz"; console.log("string",1,foo.goo,bar,foo.baz); // string 1 rad baz tubular
ãã®çµæãæž¡ããããã¹ãŠã®åŒæ°ã衚瀺ãããã¹ããŒã¹ã§åºåãããŸãã ãã¡ãããããã¯è¯ãããšã§ããããããã®ãã¹ãŠã®åŒæ°ããããã«ãã©ãŒããããããã¡ãã»ãŒãžã®åœ¢åŒã§äœããã®æ¹æ³ã§å°åºã§ããã°ããã«è¯ãã§ãããã ããããåŸ ã£ãŠãã ãã...ç§ãã¡ã¯ã§ããŸãïŒ
ä»ã®èšèªã®printfïŒïŒé¢æ°ã«ç²ŸéããŠããå Žåã¯ããæ¥ããã ããïŒconsole.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
ïŒ sãšã¯äœã§ããïŒ
ãã質åã§ãïŒ ãããã¯ã察å¿ããå€ã«ïŒåªå é äœã®é ã«ïŒçœ®ãæãããããšã¹ã±ãŒãã·ãŒã±ã³ã¹ã§ãã æ°ïŒãŸããïŒ IãŸãã¯ïŒ Fã䜿çšããããšãã§ããïŒ - ïŒ Sã¯ãïŒ Dã»ã®æååå€ãšããŠè§£éããŸãã
ãã®ãããªã·ãŒã±ã³ã¹ãåºçŸãããã³ã«ã次ã®åŒæ°ã«é çªã«çœ®ãæããããŸãã æåã®ãªã«ã¬ã³ã¹ã¯æåã®ãªã«ã¬ã³ã¹ïŒãã¡ãããæåã®è¡ã®åŒæ°ã®åŸãïŒã«ãããŸãã
åŒæ°ã䜿çšããããã®æé ã¯ãç§ãã¡ãæã£ãŠåž°ããããšæãåŒæ°ã®æ°ã$èšå·ã䜿çšããŠã圌ã«åž°å±æåã§å€æŽããããšãã§ããŸãã
var foo = {baz: "tubular", goo: "rad"}, bar = "baz"; console.log( "%2$d theory is %d %s concept. I can only describe it as %s and %s", "string",1,foo.goo,bar,foo.baz ); // 1 theory is 0 baz concept. I can only describe it as tubular and %s string
ãã°ãŒ"ïŒ "RAD"}ãããŒ= "ããº"ã var foo = {baz: "tubular", goo: "rad"}, bar = "baz"; console.log( "%2$d theory is %d %s concept. I can only describe it as %s and %s", "string",1,foo.goo,bar,foo.baz ); // 1 theory is 0 baz concept. I can only describe it as tubular and %s string
ãã®ã³ãã³ãã¯ãã2çªç®ã®åŒæ°ããå§ããŠã次ã®åŒæ°ããå§ããŸãããšèšã£ãŠããŸãã ã芧ã®ãšãããåŒæ°ã®ãªãã·ãŒã±ã³ã¹ã¯å€æŽãããŠããŸããã
æåã®åŒæ°ïŒãã©ãŒãããæååïŒãåŒæ°ã®çªå·ä»ãïŒæåããæ¥ãïŒã«é¢ä¿ããŠããŸãã ãããã£ãŠããã®äŸã§ã¯ãæåŸã®åŒæ°ã¯5çªã«ãªããŸãããããã5ã€ã®åŒæ°ã®ã¿ãæå®ããåæã«2çªç®ããéå§ããŸããã ãããã£ãŠãåŒæ°ã®æåŸã®å¶åŸ¡ã·ãŒã±ã³ã¹ã¯ååŸããããå€æŽãããŠããŸããã
ãããä¿®æ£ããã«ã¯ãæååã®åœ¢åŒãå€æŽããŠãããã€ã³ã¿ããç¹å®ã®ãã€ã³ãã§åŒæ°ã®ãªã¹ããšåæãã次ã®èŠçŽ ã«ãªããªãããã«ããŸãã ãã®åŸããã¹ãŠãæåŸ ã©ããã«æ©èœããŸãã
var foo = {baz: "tubular", goo: "rad"}, bar = "baz"; console.log( "%2$d theory is %1$s %3$s concept. I can only describe it as %s and %s", "string",1,foo.goo,bar,foo.baz ); // 1 theory is string rad concept. I can only describe it as baz and tubular
ãã°ãŒ"ïŒ "RAD"}ãããŒ= "ããº"ã var foo = {baz: "tubular", goo: "rad"}, bar = "baz"; console.log( "%2$d theory is %1$s %3$s concept. I can only describe it as %s and %s", "string",1,foo.goo,bar,foo.baz ); // 1 theory is string rad concept. I can only describe it as baz and tubular
åŒæ°ãæ£ãã衚瀺ããã«ã¯ã2çªç®ãš3çªç®ã®èŠçŽ ã®åºåé åºãå€æŽããå¿ èŠããããŸãã ä»ã®èŠçŽ ã¯ãã§ã«æ£ããäœçœ®ã«ããã®ã§ããããã®äœçœ®ã瀺ãå¿ èŠã¯ãããŸããã åŒæ°ã¯ã2ã1ã3ã4ã5ã®é åºã§äœ¿çšãããŸãã
è¡ã®æžåŒèšå®ã¯åŒ·åãªããŒã«ã§ãããæ°·å±±ã®äžè§ã ããåãäžããŸããã èªåã§éãã§ã¿ãŠãJoe Hewittsãã³ã³ãœãŒã«ã«ã€ããŠæžããŠããããšãèªãã§ãã ãã ã
ããŸããŸãªçš®é¡ã®ã¡ãã»ãŒãž
ãã°ã®ãããªã¡ãœãããããã€ããããŸãããå€èŠ³ãç°ãªããŸãã ã€ãŸãïŒconsole.infoïŒïŒãconsole.warnïŒïŒãconsole.errorïŒïŒã
console.info("%s numbers %d, %d and %d","hello",1,2,3); // hello numbers 1, 2 and 3 console.warn("%s numbers %d, %d and %d","hello",1,2,3); console.error("%s numbers %d, %d and %d","hello",1,2,3);
ãïŒ
dãšïŒ
D"ã "ããã«ã¡ã¯"ã1,2,3ïŒã console.info("%s numbers %d, %d and %d","hello",1,2,3); // hello numbers 1, 2 and 3 console.warn("%s numbers %d, %d and %d","hello",1,2,3); console.error("%s numbers %d, %d and %d","hello",1,2,3);
ãïŒ
dãšïŒ
dã®"ã "ããã«ã¡ã¯"ã1,2,3ïŒã console.info("%s numbers %d, %d and %d","hello",1,2,3); // hello numbers 1, 2 and 3 console.warn("%s numbers %d, %d and %d","hello",1,2,3); console.error("%s numbers %d, %d and %d","hello",1,2,3);
Firebugã®console.infoïŒïŒãconsole.warnïŒïŒãconsole.errorïŒïŒ
3ã€ã®ã¡ãœããã¯ãã¹ãŠã圢åŒã«åŸã£ãŠè¡ãåºåããä»»æã®æ°ã®åŒæ°ãåãå ¥ããããšãã§ããŸãã
DOMãã°
ãã°ã§DOMããŒããäœããã®æ¹æ³ã§æå®ããå¿ èŠãããå Žåãconsole.dirïŒïŒãŸãã¯console.dirxmlïŒïŒã¡ãœããã䜿çšããã®ãæåã§ãããããã®ã¡ãœããã¯ãèŠçŽ ã®ããããã£ãäžèŠ§è¡šç€ºããããèŠçŽ ã®HTMLã³ãŒãã衚瀺ãããã§ããŸãã
console.dir(document.documentElement); console.dirxml(document.documentElement);
Chromeã§console.dirïŒïŒããã³console.dirxmlïŒïŒãã芧ãã ããã
ã°ã«ãŒãã³ã°
ãã°ãã°ã«ãŒãåããŠäœæ¥ãç°¡çŽ åãããšäŸ¿å©ãªå ŽåããããŸãã ãã®ç®çã®ããã«ååšconsole.groupïŒïŒã¡ãœãããconsole.groupCollapsedïŒïŒãšconsole.groupEndïŒïŒã
console.group("Overlord"); console.log("Overlord stuff"); console.group("Lord"); console.log("Overlord stuff"); console.group("Minion"); console.log("Minion stuff"); console.groupEnd(); console.groupCollapsed("Servant"); console.log("Servant stuff");
Safariã³ã³ãœãŒã«ã§ã®ã°ã«ãŒãåã
ã芧ã®ãšãããã°ã«ãŒããžã®é£ç¶ããåŒã³åºãã«ãããµããã©ã«ããŒãäœæãããŸãã ãã©ã«ããŒãéããã«ã¯ãconsole.groupEndïŒïŒã¡ãœããã䜿çšããŸãã console.groupCollapsedïŒïŒã¡ãœããã¯console.groupïŒïŒã«äŒŒãŠããŸããããã¹ãŠã®ã³ã³ãã³ããå«ãã°ã«ãŒããæåã«æå°åããããšããå¯äžã®äŸå€ããããŸãã
ãããã¡ã€ãªã³ã°ãšèšæž¬
ã³ã³ãœãŒã«ã§ã¯ãconsole.timeïŒïŒããã³console.timeEndïŒïŒã¡ãœããã䜿çšããŠæéãæ£ç¢ºã«æž¬å®ããããšãã§ããŸãã å®è¡æéã枬å®ããã³ãŒãã®åã«æåã®åŒã³åºããé 眮ãââããã®åŸã«2çªç®ã®åŒã³åºããé 眮ãââãŸãã
console.time("Execution time took"); // Some code to execute console.timeEnd("Execution time took");
Firefoxã§ã®console.timeïŒïŒããã³console.timeEndïŒïŒã®åäœäŸ
ã¿ã€ããŒã¯ã©ãã«ã§çžäºæ¥ç¶ãããŠããããïŒæåã®åŒæ°ãšããŠæž¡ãããä»»æã®æååãæå®ã§ããŸãïŒãåæã«è€æ°ã®ã¿ã€ããŒãéå§ã§ããŸãã console.timeEndïŒïŒãæ©èœãããšãã©ãã«ãšããªç§åäœã®çµéæéãå«ãã¡ãã»ãŒãžã衚瀺ãããŸãã
æéã®æž¬å®ã«å ããŠãããªãã¯ã詳现ã«ã©ãã§ãã©ã®ãããã®æéãè²»ããããŠãããã©ãŠã¶ã瀺ããŠãããã¹ã¿ãã¯ããããã¡ã€ãªã³ã°ãã³ãŒãããã£ã¹ãã¬ã€ããããã¡ã€ãªã³ã°ããããšãã§ããŸãã
console.profile(); // Some code to execute console.profileEnd();
Chromeã§ã®ãããã¡ã€ãªã³ã°ã
ã¢ãµãŒã
è€éãªãããžã§ã¯ãã§äœæ¥ããŠãããšãã¯ããŠãããã³ãŒãããã¹ãã§ã«ããŒããããšãéèŠã§ãã ããã«ãããæããªééããèµ·ãããããªã°ã¬ãã·ã§ã³ãåé¿ãããŸãã 幞ããªããšã«ãã³ã³ãœãŒã«ã«ã¯ã¢ãµãŒããå«ãŸããŠããŸãã
ã¢ãµãŒããããšãã³ãŒãã«ã«ãŒã«ãé©çšãããã®ã³ãŒãã®å®è¡çµæãæåŸ ã©ããã§ããããšã確èªã§ããŸãã console.assertïŒïŒã¡ãœããã«ãããåºæ¬çãªã³ãŒãã®ãã¹ããå¯èœã«ãªããŸããäœãåé¡ãçºçããå ŽåãäŸå€ãã¹ããŒãããŸãã æåã®åŒæ°ã«ã¯ãé¢æ°ãåçæ§ã®ãã¹ãããªããžã§ã¯ãã®ååšã®ãã¹ããªã©ãå¿ èŠãªãã®ãæå®ã§ããŸãã
var a = 1, b = "1"; console.assert(a === b, "A doesn't equal B");
Chromeã§ã¢ãµãŒã
assertã¡ãœããã¯ãå¿ é ã®æ¡ä»¶ïŒãã®å Žåã¯ãåçŽãªå³å¯ãªåçæ§ãã§ãã¯ïŒãšã2çªç®ã®åŒæ°ãšããŠãæåã®æ¡ä»¶ãæºããããªãå Žåã«ã¹ããŒãããäŸå€ãšãšãã«ã³ã³ãœãŒã«ã«è¡šç€ºãããã¡ãã»ãŒãžãåãå ¥ããŸãã
ãã©ãŠã¶ã®ãµããŒã
ãããã®ã¡ãœããã®ã»ãšãã©ã¯éåžžã«ãããµããŒããããŠããŸãã IE8 +ãFirebugæ¡åŒµæ©èœãåããFirefoxãOperaããŸãã¯SafariãChromeãªã©ã®Webkitãã©ãŠã¶ãŒã ãã ããããã€ãã®éãããããŸããFirefoxãSafariãChromeã¯ããåºããµããŒããããŠããŸãã äºææ§ããã§ãã¯ããæãç°¡åãªæ¹æ³ã¯ããã¹ãŠã®ã¡ãœãããæã€ãªããžã§ã¯ãã®åºåã³ã³ãœãŒã«ã«ãªãconsole.dirïŒã³ã³ãœãŒã«ïŒè¡ãããšãã§ããŸãã
Dragonflyã䜿çšããOperaã¯ãè¡ã®ãã©ãŒããããšãããã¡ã€ãªã³ã°ãé€ãã»ãšãã©ã®ã¡ãœããããµããŒãããŸãïŒãããã¡ã€ã«ãprofileEndã¡ãœããã¯å®è£ ãããŠããŸããããããã¯åãªãã¹ã¿ãã§ãïŒã
IE8ã¯ãæžåŒèšå®æååãã¢ãµãŒããå«ãå€ãã®æ©èœããµããŒãããŠããŸãããã¿ã€ãã³ã°ããããã¡ã€ãªã³ã°ãdirãŸãã¯dirxmlã¡ãœããã¯ãµããŒãããŠããŸããã
firebug liteã¯ããµããŒãããŠããªããã©ãŠã¶ãŒã®ã³ã³ãœãŒã«ã«ã¡ãœãããè¿œå ã§ããããšã«æ³šæããŠãã ããã
ããã¯ã³ã³ãœãŒã«ã®å®å šãªãªã¹ãã§ã¯ãããŸãããããããã°ãšãã¹ãã®ããã»ã¹ãå€§å¹ ã«ç°¡çŽ åããæãæçšãªæ©èœããªã¹ãããŸããã ååŸããç¥èã䜿çšããæååã®ãã°ã®ã¿ã«éå®ãããŸããã
ãšã¯ã¹ãã©
ã ãããããã¯èšäºã®éåžžã«ç¡æã®ç¿»èš³ã§ããããä»ç§ã¯èªåããå°ãè¿œå ããããšæããŸãïŒ
Node.JSïŒãã©ã³ã0.2ïŒã¯ãlogãinfoãwarnãerrorãdirãtime / timeEndãassertãããã³traceã¡ãœããããµããŒãããŠããŸãã
logã¯çœ®æã®åŒæ°ã®é åºãå€æŽã§ããŸãããã眮æèªäœã¯å®è£ ãããŠããŸãã ãã¬ãŒã¹ã¡ãœãããåŒã³åºããããšãã³ãŒã«ã¹ã¿ãã¯ãã³ã³ãœãŒã«ã«è¡šç€ºãããŸãïŒãã¹ãŠã®ã¡ãœããã¯äœãè¿ãããåã«ã³ã³ãœãŒã«ã«æžã蟌ã¿ãŸãïŒã ããã¯ChromeãšOperaã§å°ãªããšãããåããŸãã
OperaãšChromeã§ã¯ãæ¢ã«ãªã¹ããããŠãããã®ã«å ããŠã次ã®ã¡ãœãããå®è£ ãããŠããŸãã
count-ã¡ãœããåŒã³åºããååšããè¡ããã§ã«å®è¡ãããåæ°ã衚瀺ããŸãã åŒæ°ã¯ãåŒã³åºãåæ°ã®åã«è¡šç€ºãããæååãæž¡ããŸãã
ãããã°-ãã°ãšéãã¯ãããŸããã
Operaã«ã¯ããŒãã«ã¡ãœããããããŸããããã¯ãçŸããåŒæ°ã®ãã¬ãŒããæ§ç¯ããã¯ãã§ãããäœãããŸããã
å®éãOperaã¯å°ãå¥åŠã§ãã è°è«äžã®æ©èœã®çµæã¯ãæšæºã³ã³ãœãŒã«ã§ã¯ãªããDragonflyã¹ããŒã¹ã§æ€çŽ¢ããå¿ èŠããããŸãïŒãã ããããã¯è«ççã§ãïŒã ããã«ããããã®ããã€ãã¯äžåºŠã«2ã€ã®å Žæã§èŠã€ããããšãã§ããŸãïŒããšã©ãŒã®ã³ã³ãœãŒã«ãã¿ããšãã¹ã¯ãªããã-> REPLã
ãŸããChromeã§ã¯ãã³ã³ãœãŒã«ãªããžã§ã¯ãã«memoryããããã£ããããŸããããã¯ãtotalJSHeapSizeããããã£ãšusedJSHeapSizeããããã£ãæã€ãªããžã§ã¯ãã§ãã ãã ããChromium Iã§ã¯ããŒã以å€ã®å€ãæã€ãããã®ããããã£ãèŠã€ããããšãã§ããŸããã§ããã