<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Little JavaScript hints, episode 1: prevent console.log breakage</title>
	<atom:link href="http://mir.aculo.us/2008/12/19/little-javascript-hints-episode-1/feed/" rel="self" type="application/rss+xml" />
	<link>http://mir.aculo.us/2008/12/19/little-javascript-hints-episode-1/</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Thu, 05 Aug 2010 21:56:08 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Michael J. Ryan</title>
		<link>http://mir.aculo.us/2008/12/19/little-javascript-hints-episode-1/comment-page-1/#comment-1695</link>
		<dc:creator>Michael J. Ryan</dc:creator>
		<pubDate>Wed, 22 Jul 2009 17:44:10 +0000</pubDate>
		<guid isPermaLink="false">http://mir.aculo.us//2008/12/19/little-javascript-hints-episode-1#comment-1695</guid>
		<description>here&#039;s mine...

//define a single reference for an empty function
if (typeof Function.empty == &#039;undefined&#039;)
	Function.empty = function(){};

//stub out full console object -- will allow debug/log statements to be left in place
if (typeof console == &#039;undefined&#039;)
	console = {
		&quot;assert&quot;: Function.empty, 
		&quot;count&quot;: Function.empty, 
		&quot;debug&quot;: Function.empty, 
		&quot;dir&quot;: Function.empty, 
		&quot;dirxml&quot;: Function.empty, 
		&quot;error&quot;: Function.empty, 
		&quot;group&quot;: Function.empty,
		&quot;groupEnd&quot;: Function.empty, 
		&quot;info&quot;: Function.empty, 
		&quot;log&quot;: Function.empty, 
		&quot;profile&quot;: Function.empty, 
		&quot;profileEnd&quot;: Function.empty, 
		&quot;time&quot;: Function.empty,
		&quot;timeEnd&quot;: Function.empty, 
		&quot;trace&quot;: Function.empty, 
		&quot;warn&quot;: Function.empty
	};</description>
		<content:encoded><![CDATA[<p>here&#8217;s mine&#8230;</p>
<p>//define a single reference for an empty function<br />
if (typeof Function.empty == &#8216;undefined&#8217;)<br />
	Function.empty = function(){};</p>
<p>//stub out full console object &#8212; will allow debug/log statements to be left in place<br />
if (typeof console == &#8216;undefined&#8217;)<br />
	console = {<br />
		&#8220;assert&#8221;: Function.empty,<br />
		&#8220;count&#8221;: Function.empty,<br />
		&#8220;debug&#8221;: Function.empty,<br />
		&#8220;dir&#8221;: Function.empty,<br />
		&#8220;dirxml&#8221;: Function.empty,<br />
		&#8220;error&#8221;: Function.empty,<br />
		&#8220;group&#8221;: Function.empty,<br />
		&#8220;groupEnd&#8221;: Function.empty,<br />
		&#8220;info&#8221;: Function.empty,<br />
		&#8220;log&#8221;: Function.empty,<br />
		&#8220;profile&#8221;: Function.empty,<br />
		&#8220;profileEnd&#8221;: Function.empty,<br />
		&#8220;time&#8221;: Function.empty,<br />
		&#8220;timeEnd&#8221;: Function.empty,<br />
		&#8220;trace&#8221;: Function.empty,<br />
		&#8220;warn&#8221;: Function.empty<br />
	};</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sean McArthur</title>
		<link>http://mir.aculo.us/2008/12/19/little-javascript-hints-episode-1/comment-page-1/#comment-744</link>
		<dc:creator>Sean McArthur</dc:creator>
		<pubDate>Fri, 19 Dec 2008 17:38:00 +0000</pubDate>
		<guid isPermaLink="false">http://mir.aculo.us//2008/12/19/little-javascript-hints-episode-1#comment-744</guid>
		<description>Even though the likelihood of this causing problems is small, I still wouldn&#039;t compare it to the variable undefined.  That comparison is only valid because you have never created that variable.  Say for some weird reason you were to say:

var undefined = null;

Your if statement will be false.  Use:

typeof window[&#039;console&#039;] === &#039;undefined&#039;;</description>
		<content:encoded><![CDATA[<p>Even though the likelihood of this causing problems is small, I still wouldn&#8217;t compare it to the variable undefined.  That comparison is only valid because you have never created that variable.  Say for some weird reason you were to say:</p>
<p>var undefined = null;</p>
<p>Your if statement will be false.  Use:</p>
<p>typeof window['console'] === &#8216;undefined&#8217;;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kangax</title>
		<link>http://mir.aculo.us/2008/12/19/little-javascript-hints-episode-1/comment-page-1/#comment-745</link>
		<dc:creator>kangax</dc:creator>
		<pubDate>Fri, 19 Dec 2008 17:38:00 +0000</pubDate>
		<guid isPermaLink="false">http://mir.aculo.us//2008/12/19/little-javascript-hints-episode-1#comment-745</guid>
		<description>Good to see you writing again!

I don&#039;t think one needs such precision (`=== undefined`) : ) Why skip things like `null` or string values (that would still throw errors when trying to invoke)

I usually use:

if (typeof console.log != &#039;function&#039;) {
  console.log = function(){ /* ... */ }
}</description>
		<content:encoded><![CDATA[<p>Good to see you writing again!</p>
<p>I don&#8217;t think one needs such precision (`=== undefined`) : ) Why skip things like `null` or string values (that would still throw errors when trying to invoke)</p>
<p>I usually use:</p>
<p>if (typeof console.log != &#8216;function&#8217;) {<br />
  console.log = function(){ /* &#8230; */ }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Thomas</title>
		<link>http://mir.aculo.us/2008/12/19/little-javascript-hints-episode-1/comment-page-1/#comment-746</link>
		<dc:creator>Thomas</dc:creator>
		<pubDate>Fri, 19 Dec 2008 17:38:00 +0000</pubDate>
		<guid isPermaLink="false">http://mir.aculo.us//2008/12/19/little-javascript-hints-episode-1#comment-746</guid>
		<description>@kangax Cools! I think I just like the === operator too much! :)

Btw, won&#039;t &quot;typeof console.log&quot; barf when there is no console object? Do you wrap it in anything else?</description>
		<content:encoded><![CDATA[<p>@kangax Cools! I think I just like the === operator too much! <img src='http://mir.aculo.us/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Btw, won&#8217;t &quot;typeof console.log&quot; barf when there is no console object? Do you wrap it in anything else?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kangax</title>
		<link>http://mir.aculo.us/2008/12/19/little-javascript-hints-episode-1/comment-page-1/#comment-747</link>
		<dc:creator>kangax</dc:creator>
		<pubDate>Fri, 19 Dec 2008 17:38:00 +0000</pubDate>
		<guid isPermaLink="false">http://mir.aculo.us//2008/12/19/little-javascript-hints-episode-1#comment-747</guid>
		<description>Yep, it most certainly will barf. I was only making a point about the actual existence check : )

Here&#039;s a `console.js` that I include in my projects (before any other scripts) http://gist.github.com/38358</description>
		<content:encoded><![CDATA[<p>Yep, it most certainly will barf. I was only making a point about the actual existence check : )</p>
<p>Here&#8217;s a `console.js` that I include in my projects (before any other scripts) <a href="http://gist.github.com/38358" rel="nofollow">http://gist.github.com/38358</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Collin Allen</title>
		<link>http://mir.aculo.us/2008/12/19/little-javascript-hints-episode-1/comment-page-1/#comment-748</link>
		<dc:creator>Collin Allen</dc:creator>
		<pubDate>Fri, 19 Dec 2008 17:38:00 +0000</pubDate>
		<guid isPermaLink="false">http://mir.aculo.us//2008/12/19/little-javascript-hints-episode-1#comment-748</guid>
		<description>Do these Firebug tricks work with Firebug 1.3bX?  Even something simple like window.console.log=function(){}; doesn&#039;t seem to stop console.log(&quot;test&quot;); from working.

To the best of my knowledge, the Firebug team changed how the console object works in 1.3 (more specifically, how it interacts with the non-privileged web page), which might be the cause.</description>
		<content:encoded><![CDATA[<p>Do these Firebug tricks work with Firebug 1.3bX?  Even something simple like window.console.log=function(){}; doesn&#8217;t seem to stop console.log(&quot;test&quot;); from working.</p>
<p>To the best of my knowledge, the Firebug team changed how the console object works in 1.3 (more specifically, how it interacts with the non-privileged web page), which might be the cause.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rakesh Pai</title>
		<link>http://mir.aculo.us/2008/12/19/little-javascript-hints-episode-1/comment-page-1/#comment-749</link>
		<dc:creator>Rakesh Pai</dc:creator>
		<pubDate>Fri, 19 Dec 2008 17:38:00 +0000</pubDate>
		<guid isPermaLink="false">http://mir.aculo.us//2008/12/19/little-javascript-hints-episode-1#comment-749</guid>
		<description>Assuming you are using Prototype, and if you want to stub out _all_ console methods, here&#039;s how.

&lt;code&gt;
if(!window.console) {
    window.console = {};
}

$A([
	&quot;assert&quot;, &quot;count&quot;, &quot;debug&quot;, &quot;dir&quot;, &quot;dirxml&quot;, &quot;error&quot;, &quot;group&quot;,
	&quot;groupEnd&quot;, &quot;info&quot;, &quot;log&quot;, &quot;profile&quot;, &quot;profileEnd&quot;, &quot;time&quot;,
	&quot;timeEnd&quot;, &quot;trace&quot;, &quot;warn&quot;
]).each(function(method) {
	if(!console[method]) {
		console[method] = function(){};
	}
});
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Assuming you are using Prototype, and if you want to stub out _all_ console methods, here&#8217;s how.</p>
<p>&lt;code&gt;<br />
if(!window.console) {<br />
    window.console = {};<br />
}</p>
<p>$A([<br />
	&quot;assert&quot;, &quot;count&quot;, &quot;debug&quot;, &quot;dir&quot;, &quot;dirxml&quot;, &quot;error&quot;, &quot;group&quot;,<br />
	&quot;groupEnd&quot;, &quot;info&quot;, &quot;log&quot;, &quot;profile&quot;, &quot;profileEnd&quot;, &quot;time&quot;,<br />
	&quot;timeEnd&quot;, &quot;trace&quot;, &quot;warn&quot;<br />
]).each(function(method) {<br />
	if(!console[method]) {<br />
		console[method] = function(){};<br />
	}<br />
});<br />
&lt;/code&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fidel Karsto</title>
		<link>http://mir.aculo.us/2008/12/19/little-javascript-hints-episode-1/comment-page-1/#comment-750</link>
		<dc:creator>fidel Karsto</dc:creator>
		<pubDate>Fri, 19 Dec 2008 17:38:00 +0000</pubDate>
		<guid isPermaLink="false">http://mir.aculo.us//2008/12/19/little-javascript-hints-episode-1#comment-750</guid>
		<description>@gonchuki: The point in referencing the Prototype.emptyFunction is in not creating a new function object each time you need a placeholder function, but instead reference to an already existing one. Remember that every object (functions in  JS are object too) need a space in memory, whereas a reference is only a pointer to an adress.

This might sound narrow-minded, but imagine large projects where every objects counts - especially with our old friend IE6, which gets pretty fast blasted with objects.
But I&#039;m sure  Thomas will handle this in his new book. ;-)</description>
		<content:encoded><![CDATA[<p>@gonchuki: The point in referencing the Prototype.emptyFunction is in not creating a new function object each time you need a placeholder function, but instead reference to an already existing one. Remember that every object (functions in  JS are object too) need a space in memory, whereas a reference is only a pointer to an adress.</p>
<p>This might sound narrow-minded, but imagine large projects where every objects counts &#8211; especially with our old friend IE6, which gets pretty fast blasted with objects.<br />
But I&#8217;m sure  Thomas will handle this in his new book. <img src='http://mir.aculo.us/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gonchuki</title>
		<link>http://mir.aculo.us/2008/12/19/little-javascript-hints-episode-1/comment-page-1/#comment-752</link>
		<dc:creator>gonchuki</dc:creator>
		<pubDate>Fri, 19 Dec 2008 17:38:00 +0000</pubDate>
		<guid isPermaLink="false">http://mir.aculo.us//2008/12/19/little-javascript-hints-episode-1#comment-752</guid>
		<description>what stops me from using function(){} ?

I don&#039;t get why the need to plug Prototype when using a *literal* empty function is a lot more clear.

btw, for people that give firebug a serious use, defining log is not enough, this is the desirable solution:

window.console = {log: function(){}, warn: function(){}, error: function(){}, info: function(){}};</description>
		<content:encoded><![CDATA[<p>what stops me from using function(){} ?</p>
<p>I don&#8217;t get why the need to plug Prototype when using a *literal* empty function is a lot more clear.</p>
<p>btw, for people that give firebug a serious use, defining log is not enough, this is the desirable solution:</p>
<p>window.console = {log: function(){}, warn: function(){}, error: function(){}, info: function(){}};</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Thomas</title>
		<link>http://mir.aculo.us/2008/12/19/little-javascript-hints-episode-1/comment-page-1/#comment-753</link>
		<dc:creator>Thomas</dc:creator>
		<pubDate>Fri, 19 Dec 2008 17:38:00 +0000</pubDate>
		<guid isPermaLink="false">http://mir.aculo.us//2008/12/19/little-javascript-hints-episode-1#comment-753</guid>
		<description>@gonchuki You&#039;re right of course that you can just use plain ol&#039; function(){}, but sometimes I prefer having more literal code (when I will glance over this code later, using emptyFunction instantly makes clear what&#039;s going on).

I doubt that the warn/error/info functions are that much used (very rarely do so myself), but YMMV. Thanks for the snippet!</description>
		<content:encoded><![CDATA[<p>@gonchuki You&#8217;re right of course that you can just use plain ol&#8217; function(){}, but sometimes I prefer having more literal code (when I will glance over this code later, using emptyFunction instantly makes clear what&#8217;s going on).</p>
<p>I doubt that the warn/error/info functions are that much used (very rarely do so myself), but YMMV. Thanks for the snippet!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

