Matt Snider JavaScript Resource

Understanding JavaScript and Frameworks

Saturday, August 2, 2008

Boolean Functions

There is very little you need to attach to Boolean, as it is a very simple object. I have only found two methods that I like to attach to the ‘Boolean’ Object: ‘is’ and ‘get’. The ‘is’ method is a type detection like I have attached to other native JavaScript objects. The ‘get’ method is to convert falsy/truthy values into ‘false’ and ‘true’. While this isn’t necessary because you can use “! yourObject”, however I frequently like to use strict, type comparisons operations, such as ‘===’ and ‘!==’.

Check out object.js here and the unit test here.

As a side note, I have been updating the blog layout a bit. Hopefully, I am making this blog more useful.

posted by Matt Snider at 5:33 pm  

3 Comments »

  1. The strict comparison operators (=== and !==) should not be the issue here. The logic operators (&& and ||) are probably the most relevant operators in the context of your get function.

    There’s no reason to convert something boolean and then check whether or not it’s equal to a boolean value. if( Boolean.get( obj ) === true ) can be written as if( Boolean.get( obj ) ). If you want it to be false just throw in the ! operator.

    The new layout isn’t vastly different, which is good. The only thing I’d suggest, and this could be my browser, is to indent the sub-categories a little more.

    Comment by MillsJROSS — August 5, 2008 @ 5:55 am

  2. Thanks MillsJROSS, you make a good point. Also, I have updated the sub-categories. Please, let me know if this works better in your browser.

    Comment by Matt Snider — August 5, 2008 @ 10:28 am

  3. The sub-categories are looking much better now. Thanks!

    Comment by MillsJROSS — August 6, 2008 @ 4:57 am

RSS feed for comments on this post. TrackBack URI

Leave a comment

Powered by WordPress