 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.)
 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.)Alert.go =''; //-  ;   DEBUG = true; ,    ; Alert.go ='.'; //-   -,  ''.Alert() (  Alert     -  ,  1); Alert.go ='.*'; //    ,    ,  2; delete Alert.go; //-  ; Alert.go ='fthghhfgh'; // -; Alert.go ='^(aab|xaa==|test45:|xxx|__)$'; //-    ( -).  Alert(aaa, bbb,'====', ); //  console.log() 'xaa=='.Alert(xaa, xx.element, xaa(1)); //,   -       '-test-'.Alert('   , ', Alert);  ...else if (window.opera && opera.postError) {opera.postError(arguments);}  /** * / "--", spmbt0, 30.07.2011 * @context (String) :  ,    * @property go: .     undefined,    * @param o: ,   1     */ Alert = function(o){ if(Alert.go===undefined) return; //===  === var alertInner = function(x, xx,a,b,c,d,e){ //x:  ( FF5 -  7,  Firebug   ) var aL = arguments.length; if(!window.console){ for(var i =0, args =[]; i < aL; i++) args[i] = arguments[i]; alert(args); }else if(console.log.apply) console.log.apply(console, arguments); else{ // - 5- FF    console.log.apply if(aL ==1) console.log(x); else if(aL ==2) console.log(x, xx); else if(aL ==3) console.log(x, xx, a); else if(aL ==4) console.log(x, xx, a, b); else console.log(x, xx, a, b, c, d, e); } }, hasContext = this !== window , context = this; if(hasContext && context instanceof String){ if(!RegExp(Alert.go,'g').test(context)) //===  === return; for(var i =1, args =[]; i <= arguments.length; i++) args[i] = arguments[i -1]; args[0] = "'"+ context +"':"; alertInner.apply(window, args); //===console.log      === }else{ //  .   {from:'', ...} if(Alert.go =='.' || Alert.go =='.*') return; //===  === if(o && o.from && o.from !=''){ //        "from",    var args =[], j =1; for(var i in o) if(i !='from'){ args[j++] = '{'+ i +'}'; args[j++] = o[i]; } if(arguments.length >1) // args[j++] ='}; '; for(var i = 1, aL = arguments.length; i < aL; i++) //   args[j++] = arguments[i]; args[0] = "'"+ o.from +"':"; alertInner.apply(window, args); //===console.log    "from"   === }else alertInner.apply(window, arguments); //=== console.log=== } } String.prototype.Alert = Alert; Alert.go =''; //  //Alert.go ='test-'; //       (   Alert() ) To view the resulting content in the console - do:
Source: https://habr.com/ru/post/125308/
All Articles