Firebug adds a global variable called “console” to each webpage loaded in Firefox. This object contains many methods that allow you to write to the Firebug console and display information passing through the scripts.firebug.ru
Chrome 28.0.1500.72 m,
Firebug 1.11.3,
Firefox 22.0,
Opera 12.15 (version before leaving presto)
+
+
±
± console.log
+
+
-
± console.assert
+
+
+
+ console.clear
±
+
-
± console.count
±
±
±
± console.debug
±
±
±
+ console.dir
±
±
-
± console.dirxml
+
±
±
± console.error
-
±
-
± console.exception
+
+
±
+ console.group
+
+
-
+ console.groupCollapsed
+
+
+
+ console.groupEnd
±
+
+
+ console.info
+
+
-
- console.profile
+
+
-
- console.profileEnd
±
+
-
- console.table
±
±
±
± console.time
±
±
±
± console.timeEnd
-
±
-
- console.timeStamp
+
+
±
± console.trace
+
+
+
+ console.warn
+
+
±
±var a = ' '; console.log(a); console.log(' ', 12, true, [1,2,3], {a:1,b:2}); console.log('Node', document.getElementsByTagName('body')); console.log('DOM', document); console.log('', alert); console.log('', NaN, null, undefined);
Chrome ->
Firebug ->
Firefox ->
Opera
±
±
±
-| Pattern | Description |
|---|---|
| % s | Line. |
| % d or % i | Number. |
| % f | Floating point number Firebug's official documentation is blatantly lying "(numeric formatting is not yet supported)" - don’t believe it |
| % o | DOM element Firebug displays as a link to the item. Chrome, in addition to the link, also knows how to display this element in the console itself. In the current version 28.0.1500.72 m there is a bug (?) - each time updating the page, the DOM console is displayed alternately as DOM, then as a Javascript object. Firefox on click, opens the item in a modal window. (all attributes and methods of this object are available in it). |
| % O | JavaScript object Not supported in Firefox. Chrome in the case when not just an object gets into% O, but DOM converts it into a js object (all methods and attributes are available). Firebug does not distinguish% o from% O. |
| % c | css style (color, background, font). Not supported in Firefox. |
console.log(' %d %s',10,''); console.log(' %f',Math.PI); console.log('%c %c %c%c ','color:red;','font-size:16px;color:orange;','background:black;color:yellow;','font:normal;color:normal;background:normal;'); console.log('body as DOM: %o',document.getElementsByTagName('body')[0]); console.log('object: %O',{a:1,b:2}); console.log('body as Object: %O',document.getElementsByTagName('body')[0]); 
The bottom line is that the console object can be implemented differently in different environments. In some cases, the object is implemented with full, albeit native functions, that is, if you try to display console.log.toString (); we get instead of the source code of the [native code] function. In some environments, as I understand it, this object simply provides things that can be called with parentheses, but they are not full functions: they cannot be called with call / apply / bind. From examples: Chrome debugger and IE debugger.
The main disadvantage:
Let there is an EventEmitter and we want to activate its activation. To do this, it is enough to sign some logger on it, for example console.log.object.on('event', console.log);
That is, console.log will be called with all parameters with which any callback on this emitter is called. You can replace it with console.dir, then in some environments (Node.js) there will be a more detailed output of the first parameter. In any case, if console.log, console.dir are not functions, they cannot be called, you have to write a binding. Moreover, in the case of console.log, the binding will be incomplete: we will not be able to pass all the parameters, because we cannot make apply.function log (a1, a2, a3) { console.log(a1, a2, a3); // arguments, apply }And there is only one solution - without grace.
In general, functions must be functions.
+
+
-
± console.assert(2>1); console.assert(1>2); console.assert(2>1,' '); console.assert(1>2,' '); console.assert(1>2,'',''); console.assert(1>2,' : [%s]',''); console.assert(1>2,'','',1,2,3,{a:1}); 
+
+
+
+
±
+
-
± console.count(); console.count(); // console.count(''); console.count(''); // Chrome console.count('','',''); console.count(document); for (i=0;i<2;i++) console.count(); // for (i=0;i<2;i++) console.count(''); // 
±
±
±
± var a = ' '; console.debug(a); console.debug(' ', 12, true, [1,2,3], {a:1,b:2}); console.debug('Node', document.getElementsByTagName('body')); console.debug('DOM', document); console.debug('', alert); console.debug('', NaN, null, undefined); console.debug(' %d %s',10,''); 
±
±
±
+ console.dir(' '); console.dir([1,2]); console.dir({a:1}); console.dir([1,2],{a:1}); console.dir(document); 
±
±
-
± console.dirxml(' '); console.dirxml([1,2]); console.dirxml({a:1}); console.dirxml(document); console.dirxml([1,2],{a:1}); 
+
±
±
± console.error(); // console.error(' '); console.error(' ', 12, true, [1,2,3], {a:1,b:2}); console.error(' %d %s',10,''); (function firstlevel () { (function secondlevel () { (function lastlevel () { console.error(' '); })(); })(); })(); console.error(new Error(' ')); // 
-
±
-
± console.exception(); // console.exception(' '); console.exception(' ', 12, true, [1,2,3], {a:1,b:2}); console.exception(' %d %s',10,''); (function firstlevel () { (function secondlevel () { (function lastlevel () { console.exception(' '); })(); })(); })(); console.exception(new Error(' ')); // 
+
+
±
+
+
+
-
+
+
+
+
+ console.log(' '); console.group(); // console.log(' '); console.group(' ', '', '', '', 12, true, [1,2,3], {a:1,b:2}); console.log(' '); console.group(' %c', 'color: red;'); console.log(' '); console.groupCollapsed(' '); console.log(' '); console.groupEnd(); console.log(' '); console.groupEnd(); console.log(' '); 
±
+
+
+ var a = ' '; console.info(a); console.info(' ', 12, true, [1,2,3], {a:1,b:2}); console.info('Node', document.getElementsByTagName('body')); console.info('DOM', document); console.info('', alert); console.info('', NaN, null, undefined); console.info(' %d %s',10,''); 
+
+
-
-
+
+
-
- console.profile(); (function someFunction() { for (i=0;i<10000000;i++) {var s='a'; s+='a'; delete s;} })() console.profileEnd(); console.profile(" "); (function someFunction() { for (i=0;i<10000000;i++) {var s='a'; s+='a'; delete s;} })() console.profileEnd(); 
±
+
-
- var table = []; table[0] = [1,'2',[1,2,3]]; table[1] = [document,document.getElementsByTagName('body'),window]; table[2] = [{a:1},null,alert]; console.table(table); function Person(firstName, lastName, age) { this.firstName = firstName; this.lastName = lastName; this.age = age; } var family = {}; family.mother = new Person("", "", 32); family.father = new Person("", "", 33); family.daughter = new Person("", "", 5); family.son = new Person("", "", 8); console.table(family); 
±
±
±
±
±
±
±
±
-
±
-
- console.timeStamp(); console.time(' '); (function someFunction() {for (i=0;i<1000000;i++) {var s='a'; s+='a'; delete s;}})() console.time(' '); (function someFunction() {for (i=0;i<1000000;i++) {var s='a'; s+='a'; delete s;}})() console.timeEnd(' '); (function someFunction() {for (i=0;i<1000000;i++) {var s='a'; s+='a'; delete s;}})() console.timeEnd(' '); console.timeStamp(' '); console.time(12); (function someFunction() {for (i=0;i<1000000;i++) {var s='a'; s+='a'; delete s;}})() console.timeEnd(12); console.time(document.getElementsByTagName('script')); (function someFunction() {for (i=0;i<1000000;i++) {var s='a'; s+='a'; delete s;}})() console.timeEnd(document.getElementsByTagName('body')); console.time(1,2,3); // (function someFunction() {for (i=0;i<1000000;i++) {var s='a'; s+='a'; delete s;}})() console.timeEnd(1,3,2); console.time(); // (function someFunction() {for (i=0;i<1000000;i++) {var s='a'; s+='a'; delete s;}})() console.timeEnd(); console.timeStamp(' '); For Opera tests, the lines with timeStamp had to be commented out.
+
+
±
± console.trace(); (function firstlevel () { (function secondlevel () { (function lastlevel () { console.trace(' '); })(); })(); })(); 
+
+
+
+ var a = ' '; console.info(a); console.info(' ', 12, true, [1,2,3], {a:1,b:2}); console.info('Node', document.getElementsByTagName('body')); console.info('DOM', document); console.info('', alert); console.info('', NaN, null, undefined); console.info(' %d %s',10,''); 
Source: https://habr.com/ru/post/188066/
All Articles