Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8788411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:08:17+00:00 2026-06-13T22:08:17+00:00

I have a function like this: getData = -> $(‘body’).data(‘key’) I have another function

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:08:19+00:00Added an answer on June 13, 2026 at 10:08 pm

    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/

    getData = ->
      $('div').data 'key'
    
    getData2 = ->
      $('div').data 'foo', 'bar'
    
    otherFunction = ->
      if getData()
        console.log 'yep'
      else
        console.log 'nope'  <--- Resolves false
    
      if getData2()
        console.log 'yep'   <--- Resolves true
      else
        console.log 'nope'
    
    otherFunction()
    

    You may have some other issue at play…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that looks like this: // Fetch 1 MB of data
Suppose I have a function like this (I use akka 2.0.2): def foo(message: String):
I have a C function like this: void get_data(const obj_t *obj, short const **data,
I have a function like this, that I would like to refactor function Myfunction(sUrl,
I have one function like this -(NSMutableArray *)getData { NSMutableArray *tempArr=[NSMutableArray alloc]init]; // perform
I have coded like this: $.ajax({ cache: false, url: /Admin/Contents/GetData, data: { accountID: AccountID
I have function like this: function ypg_delete_img($id, $img) { $q = $this->ypg_get_one($id); $imgs =
I have function like this: function gi_insert() { if(!IS_AJAX){ $this->load->library('form_validation'); $this->form_validation->set_rules('name', 'Naslov', 'trim|required|strip_tags'); $this->form_validation->set_rules('body',
I have a function like this void doSmth(Long... paramg){ } But I can't pass
I have a function like this: MyFunction(double matrix[4][4]) {/*do stuff*/} I am calling this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.