funjs / book-source

The example source code for the book Functional JavaScript by Michael Fogus, published by O'Reilly
Other
349 stars 101 forks source link

existy() and truthy() #1

Closed cdcme closed 11 years ago

cdcme commented 11 years ago

Awesome book. I love it.

About your helper predicates, existy() and truthy(), couldn't you just do:

function existy(x) { return x != null; }
function truthy(x) { return !!x; }

Granted, it doesn't really illustrate the idea of composing functions from functions but is more succinct, I think.

fogus commented 11 years ago

Hi and thank you for the kind words. The goal of truthy is to simplify the truthiness in JavaScript to a model like Ruby (as one example): null and false are falsey and everything else is truthy. If I use !!x then I'm right back into 0 and '' being falsey -- the thing I was hoping to avoid. :-)

cdcme commented 11 years ago

Oh yeah, of course! Thanks!