JavaScript Tip: Bust and Disable console.log

Here’s a quick and dirty follow-up to my original Save me from console.log errors. The main improvement to this version is that it includes a way to disable console.log (and related functions), for example, in production environments.

While console.log is awesome, you really don’t want your dirty inner workings littering up the Console (or visible to the user — though, you could make an argument that this is a great way to debug errors in live environments) once your app is deployed.

Note: Firebug can get unhappy sometimes if you try to mess with its console object. But, in theory, this approach should work.

var DEBUG_MODE = true; // Set this value to false for production

if(typeof(console) === 'undefined') {
    console = {}

if(!DEBUG_MODE || typeof(console.log) === 'undefined') {
    // FYI: Firebug might get cranky...
    console.log = console.error = = console.debug = console.warn = console.trace = console.dir = console.dirxml = = console.groupEnd = console.time = console.timeEnd = console.assert = console.profile = function() {};

[[Prototype]] vs prototype (Peter van der Zee on JSMentors)

Here’s a great explanation (by Peter van der Zee) of the key differences between [[Prototype]] and prototype in JavaScript. It finally makes sense now!

Note: to understand this explanation it would help to know what prototype is/does and how it works.

So we have [[Prototype]] and prototype. You can see prototype as the parent object to which [[Prototype]] (so __proto__) refers to on instances of the constructor. Hah, I’m sure that’s not confusing. So let me give an example :)

var A = function(){};
var a = new A();
log(a instanceof A); // true
log(A.prototype); // object
log(a.prototype); // undefined
log(a.__proto__); // object, in browsers that support the mapping
log(a.__proto__=== A.prototype); // true.

“A” has a prototype property (A.prototype). If you add new properties to that object, they will automagically be available on “a”. “a” has a [[Prototype]] internal property. It refers to A.prototype. It is an essential part of the prototypal chain because it actually determines the next part of the chain. If you change a.[[Prototype]], changes to A.prototype will no longer be reflected on “a”. In fact, all not “own” properties of a will no longer be accessible and are replaced by a new set of properties.

via [JSMentors] Object creation.

Dogfooding Edit Flow

Note: Most of the code here is specific to my environment on Webfaction, github and for use with WordPress plugins. You can make it work for other setups (i.e. different hosts, local gits, or even SVN) but will involve some tweaking.

Scott recently had a great idea to run the bleeding edge release of Edit Flow on our official site. I usually do this for most of my plugins before releasing, though, it’s a manual process: FTP up the latest code and give it a test run. That’s not fun.

Here’s a far better, automatized way to keep your repo up-to-date. You can either use cron or githooks. Pick your poison.

Continue reading