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 8434569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:41:33+00:00 2026-06-10T06:41:33+00:00

There are many JavaScript functions out there that accept an object directly here are

  • 0

There are many JavaScript functions out there that accept an object directly here are some examples. This is isn’t specific to either of these functions jquery’s $.ajax() or the nodejs module request(), both are just examples.

$.ajax({
  method: "post",
  data: {'hello':'world'},
})

request({
  method : "post",
  body : "hello world",
});

I just tried something that I thought would work and it was a more elaborate version of this.

request({
  method : function(){
    return "post";
  },
  data: {'hello':'world'},
});

To my surprise it didn’t work. Neither does this.

var m = function(){
  return "post";
};

request({
  method : m,
  data: {'hello':'world'},
});

Am I missing something? Is there some way to get a generated function into these objects? I’d love some feedback.

  • 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-10T06:41:34+00:00Added an answer on June 10, 2026 at 6:41 am

    You don’t want to pass a function here, you want to pass its return value.

    request({
      method: (function() {
        return "post";
      })(),
      data: {'hello':'world'}
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are many errors here in SO, but this scenario I think its different.
There are many questions like this but I can't find one that seems to
There are so many web based calendars out there that I'm not sure which
I can see there are many ways to use jQuery safely in the javascript
I'm new at javascript and while there are many more complex solutions, I don't
I need help with Javascript. I need to replace however many characters there are
There are many similar questions, but I didn't find one that gets straight to
As I'm writing JavaScript I'm always missing some fairly basic language features that JavaScript
There are other questions about this in other languages , and other non-lazy JavaScript
Are there any examples out there on how to integrate HTML5Boilerplate into Symfony? The

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.