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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:10:37+00:00 2026-05-18T20:10:37+00:00

What does the following javascript code mean? I guess it’s defining a function within

  • 0

What does the following javascript code mean? I guess it’s defining a function within a function to make it look like OOP? Why the function can return multiple functions? what is the bracket at the end?

var grid_ui = function () {

    function setup_data_source() {}

    return {
        init: function () {},

        set_ds: function(rpt_headers, rpt_rows) {}
    } // return
}();
  • 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-05-18T20:10:37+00:00Added an answer on May 18, 2026 at 8:10 pm

    The { } notation is called an object literal. It is same as:

    a = new Object();
    a.init = function() { };
    a.set_ds = function(...) { };
    return a;
    

    and return { } returns an object.

    The function () { ... }(); is a self-invoking function: it creates an anonymous function them immidiately invokes it.

    In your code, the self-invoking function returns an object of functions, which is a namespace pattern. The value of grid_ui now contains { init: ..., set_ds: ... }, which is mentioned in return.

    These concepts are very difficult to explain in one SO answer, so I will provide you some links:

    • http://www.hunlock.com/blogs/Functional_Javascript/
    • http://www.dustindiaz.com/namespace-your-javascript/
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following JavaScript code: Link In which the function makewindows does not
What does the following mean? Class.Function(variable := 1 + 1) What is this operator
I tried following code: <script type=text/javascript> $(document).ready(function(){ $(image).hover( function () { $(this).append($(<span> ***</span>)); },
Why does the following code sometimes causes an Exception with the contents CLIPBRD_E_CANT_OPEN: Clipboard.SetText(str);
Why does the following code not work as I was expecting? <?php $data =
What does the following code do in C/C++? if (blah(), 5) { //do something
What does the following code do? A link to something in the PHP manual
What does the following error mean? Geeneration of designer file failed: Exception from HRESULT:
Why does the following code print ‘read(): Resource temporarily unavailable’ 80% of the time?
While testing JavaScript code in Firefox 3.5 I sometimes get the following error: Component

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.