Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
if (typeof(console) != 'object') {
var firebug = {env: {css : "PATH_TO_CSS/firebug-lite.css"}};
var doc = window["document"]||null;
var script = doc.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src' , "PATH_TO_FIREBUGLITE/firebug-lite-compressed.js");
doc.getElementsByTagName('head')[0].appendChild(script);
}
var MyTools = {
debug: {
isOn: false
}
}
// ...
// где-то в коде:
if (MyTools.debug.isOn)
console.log(some_var)
* This source code was highlighted with Source Code Highlighter.var MyTools = {
debug: {
isOn: false,
log: function() {
if (this.isOn && window.console)
console.log.apply(console, arguments);
},
stop: function() {
if (this.isOn)
debugger;
}
}
};
// ...
// где-то в коде:
MyTools.debug.log(some_var);
MyTools.debug.stop();
* This source code was highlighted with Source Code Highlighter.ProjectNamespace.log = function ()
{
if (! ProjectNamespace.MUTED_CONSOLE
&& typeof(console) != 'undefined'
&& typeof(console.log) == 'function')
{
console.log.apply(null, arguments);
}
};
}
alert({x:3, y:5}) --> [object Object]
alert(document.body) --> [object HTMLBodyElement]console.log({x:3, y:5}) --> { 'x': 3, 'y': 5 }
console.log(document.body) --> <BODY class="timeline" id="home">if (typeof console === 'undefined') {, а там консоль определена.Recommended ConfigurationНе слабо.
Firefox 3.7a1pre
Firebug 1.5b1
Eventbug 0.1a2
var MyObj = {
property1 : "qwerty",
property2 : 100500,
anotherProperty : true,
method1 : function() {
// do something
},
toString : function() {
return "{\n" +
" property1 : " + this.property1 + ",\n" +
" property2 : " + this.property2 + ",\n" +
" anotherProperty : " + this.anotherProperty + "\n" +
"}";
}
};
{
property1 : qwerty,
property2 : 100500,
anotherProperty : true
}
var MyObj = {
property1 : "qwerty",
property2 : 100500,
anotherProperty : true,
method1 : function() {
// do something
}
};
if(MyObj)
{
MyObj.toString = function() {
return "{\n" +
" property1 : " + this.property1 + ",\n" +
" property2 : " + this.property2 + ",\n" +
" anotherProperty : " + this.anotherProperty + "\n" +
"}";
}
}
if(typeof allow_console == 'undefined'){
var allow_console= false;
var hash = location.hash;
if(hash.indexOf('#console')!=-1){
allow_console = true;
}
}
if(allow_console==true){
console.log('Режим отладки включен');
}
Отладка Javascript