Re:Ask HN: JavaScript dev environment ?
by antichaos on Saturday July 03, 2010 @01:46PM
(#1484117)
What's wrong with Firebug? I fail to find a better alternative for JS debugging.
[ Parent
| on HN ]
Re:Ask HN: JavaScript dev environment ?
by hundredwatt on Saturday July 03, 2010 @02:13PM
(#1484170)
I have run into problems in the past caused by forgetting to remove console.log() lines from my scripts. If the console wasn't open, then the scripts didn't work.
This isn't a huge problem or reason not to use Firebug (which I would be totally lost without), just something to be wary of.
if(!console)console={log:function(){}};
You're welcome.
Re:Ask HN: JavaScript dev environment ?
by marcuswestin on Saturday July 03, 2010 @02:39PM
(#1484219)
This will throw if console is not defined. Try
if (!window.console)
Or if (typeof console == 'undefined')
Or if !('console' in window))
NDoesn't here. What are you using?
My solution to this issue was to write a console2.log helper function and call that instead of the original console.log:
var console2 = {
log: function(msg){
if(typeof console != 'undefined'){
console.log(msg);
}
}
}You can solve(?) this by creating a dummy console.log object when one isn't already present, then throwing away all of the output.
if(!window.console){window.console = {};}
if(!(toString(window.console.log) === '[object Function]')) {window.console.log = function(){};}
there, fixed..
This won't work in node. That's not a huge deal, but it's pretty simple to come up with a cleaner solution that works in all environments.
if (window.console) console.log(...);
Re:Ask HN: JavaScript dev environment ?
by jackowayed on Saturday July 03, 2010 @02:40PM
(#1484222)
That really should be built in to console.log.
I may not be entirely sober yet but I believe the problem at hand is what happens when window.console isn't defined at all.
It can be, but only if console.log is defined in your source code. It isn't when you use Firebug, so it won't be when you're not using Firebug.
Chrome Dev Tools.
Yea those have some fancy live JS editing capability, where you can edit the JS, it runs the code with the changes but without restarting the whole program.