Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've installed firebug and I wrote all these log statements.

I've tested my app in IE and of course I've got "undefined" error.

What's the common idiom to avoid this.

I don't really feel like commenting all the console.log statements in my file nor to mock them.

Well I'm not sure what to do.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
166 views
Welcome To Ask or Share your Answers For Others

1 Answer

i usually make a wrapper function like so:

function log(obj) {
    if (window.console && console.log) console.log(obj);
}

or you could do something like this at the beginning of your script file/element:

if (!window.console) { 
    window.console = {
        log: function(obj){ /* define own logging function here, or leave empty */ }
    };
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...