
Good
console.log , and there is no place to extol further. And is not supported everywhere, and suffers from multi-letter. And the task appears to have a simple function, as flexible as console.log (or more), but adapted to different browsers without rework to display one or more values. In debugging, text explanatory headers are often needed in a string, so it turned out to be convenient to have a method added to a string (a String object) with the name
Alert , which performs the same thing as
console.log and outputs the context string in front of the argument list. (The string is in apostrophes, because it is then convenient to copy and search through codes where such a title is written.)
Going deeper into the variety of commands in the implementations of each browser turns out to be unnecessary, because it loses its meaning when checked in another browser. And a long finishing of the ideal product is simply unprofitable, it requires professional recessing, in particular, and then tracking new products, errors and their elimination. We need a completely simple scheme of work, which will be easily completed if something is needed additionally and using the basic capabilities of debug consoles.
The system is a bit more complicated than the definition of console.log itself (internal
alertInner function), and has the following advantages:
1) only 2 new words, and those are familiar;
2) words are shorter than K.O'Ns ... (and so on);
3) does not replace other used names,
4) much easier than other complex scripts,
5) the code is easy to read and customize.
Normal
alert () participates in this system as the worst alternative to output. But it can also produce several values ​​separated by a comma at a time (for example, in IE8 without DebugBar enabled).
')
Often, two basic actions are required: disable all debugging with one command; disable most debugging, if you are forced to watch alerts in small volumes or just have a desire to see some messages. Context lines are good for this. We will include only those messages in the headers of which there are samples of the (greedy) regular expression:
Alert.go ='';
(For convenience, 2 exceptions and 1 customization are embedded in the code. The latter can be thrown away or vice versa, but exceptions are useful and understandable. You need to have a whole range of actions: deny everything, allow functions, allow methods, allow both, allow methods filter and without - without increasing the command system.)
Run:
Alert(aaa, bbb,'====', );
Thus, it is convenient and intuitive to launch different outputs on different debug pages. The tool remains extremely simple (only 3 functions under one name, each of which is familiar and in demand), although there are reserves for increasing monospecificity - if you put the name of a handler function or hash that describes the output table into the context, you can go far. Or, for example, I added a special output to the code for messages of the form
Alert ({from: '- test-', xx: other parameters ...}); . Usually this format is not needed, because is forgotten; but its plus is that the first argument, the hash is viewed disassembled, sometimes it is needed to be shown in simple alerts and in HTML.
The same message system can be embedded in the working draft as an application for other events, under a different name and output not into the console, but into a well-designed block, if they are for the user, or transferred to the server.
For the console, earlier in Opera it was necessary, now it is not necessary (there is a Dragonfly-console, Ctrl-Shift-I, then the "> _" icon):
...else if (window.opera && opera.postError) {opera.postError(arguments);}
... Recently, here FF5 (or firebug?) Spoiled the picture, refusing to understand console.log.apply, had to add an ugly alternative. How to bypass the bug did not come up, and not necessarily. Rarely the number of arguments is greater than 7 and you can always put them into an array.
Function code:
Alert = function(o){ if(Alert.go===undefined) return;
To view the resulting content in the console - do:
Firefox : if available Firebug - Ctrl-Shift-L (command line); without it -
no one knows :);
Chrome : Ctrl-Shift-J (Javascript console);
Safari : Ctrl-Alt-C (error console);
IE : so that it is not displayed by alerts, open DebugBar or something similar;
Opera : messages are visible in the error console (Ctrl-Shift-O), but there with garbage; more conveniently - in Dragonfly (Ctrl-Shift-I, then the "> _" icon).
See the script with examples here:
spmbt.kodingen.com/function/testAlert.htm .

Question (survey): who uses nonmonstrous solutions for debugging?
*) I’ll add to the literature that Firebug has a feature that is extremely difficult to find in the descriptions if you don’t know what it's called. It is called "
debugger; ". If such a name is found in javascript, Firebug will stop like a normal breakpoint, the further start of the program is from the Script tab by clicking on “Continue (F8)”.
weirdan wrote: - This feature is in ECMA-262-5 and is supported in both Fx and IE.0. Firebug
Command Line API .
0.1 Released Firebug 1.8 (supported in Firefox 5.0).
Detailed information (on Habré) on the new features of the version .
About the console on Habré:
1. “Debugging Javascript in various browsers and environments” , January 24, 2009,
lomaster2. Use console to the full , February 26, 2011, Ryan Seddon
3. Remote debugging of Javascript , March 3, 2011, youtu.be ...
4. Modern JavaScript Debugging , February 7, 2009, Chris Mills, Hallvor ...
5. Using Debugging Tools , August 27, 2008, Pamela Fox, Google M ...