Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I did the same; I had a simple "def()" and "undef()" function pair, which shrank the code base a tiny bit and made it terribly easy to understand what conditions I was testing for.

Unfortunately, I recently profiled my code and found that those functions were being called an absurd number of times during a moderately complicated page load, so they're gone now. :-(



Yeah. Although, in modern browsers, the overhead is really trivial.

I just tried timing it in modern Chrome. The overhead of calling a function like isDefined(), versus typeof x !== 'undefined', seems trivial. On my machine, after 100,000 calls there's a difference of 50ms.

Still, I concede that there are some situations where it would matter, if you were driving an animation. And in older browsers it might matter a lot even in other circumstances.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: