I have a function like this:
getData = ->
$('body').data('key')
I have another function that I want to use the first function to check if there’s some data. What I want to write is this:
otherFunction = ->
if getData()
...do something...
However, in my testing the statement if function() will always be true, because there’s something there (a function). So the above doesn’t work.
What’s the cleanest way to do what I’m attempting here, check that a function returns some data?
Your pattern will definitely resolve to false (because of a falsy return value) if there is no data attribute, or there is an empty data attribute on a dom element.
See this example: http://jsfiddle.net/wkGcW/1/
You may have some other issue at play…