Let's talk about some code (Javascript)

« Previous article:   Next article: »
One thing after another.... Blog Home Death Forecast

Ya’know, I’d always intended this blog to be one of them cool “.Net Blogs”, with just a occasional entry about my life. Ok, so two years later, I’ve got the occasion random life entry thing down, but in all the time, not one thing about programming. Let’s try correcting that.

Lately, I’ve been reading The JavaScript Anthology: 101 Essential Tips, Tricks & Hacks The JavaScript Anthology, which is otherwise a fine book on Javscript technique. ( website ) However, every now & then, the authors just get a bit caught up in “clever” code. For example, this snippet from pg. 178 :

Now, the important thing to note here, is that nearly every line is affected by the value of targetvisibility, and we test for that value 4 times in just that short function. Now, let’s consider if we just tested for it once :

So, now while, it’s a bit longer, it’s a whole bunch easier to read & understand. But let’s take this a step further. How do we initially call this function Again, from pg. 178 :

The significance of this is that now, nowhere is the targetvisibility parameter not set explicitly. In which case, there’s no need for it:

comments powered by Disqus