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

  • Home
  • SEARCH
  • 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 5965973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:43:23+00:00 2026-05-22T19:43:23+00:00

Its a general question about something i seem to encounter a lot: When should

  • 0

Its a general question about something i seem to encounter a lot:
When should i use

function Bla(){return function(){alert("bla");}}

and call the main function Bla,
and when should I use

function Bla(){function innerBla(){alert("bla");}}

and call Bla.innerBla?

What is the difference between them?

  • 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-22T19:43:24+00:00Added an answer on May 22, 2026 at 7:43 pm

    Those are two different ways of doing things, and they operate differently.

    The first one is a function that returns another function. Thus, to invoke the inner function, you need to first call the outer one, Bla, (which returns the inner one) and then invoke the returned value (the inner function):

    function Bla(){
        return function(){
          alert("bla");
        }
    }
    
    Bla()(); // will alert "bla"
    

    The second one just defines an inner function, and there’s no way of invoking that inner function from outside of the outer function because it’s scoped only within the outer function Bla:

    function Bla(){
        function innerBla () {
          alert("bla");
        }
    }
    
    Bla(); // will do 'nothing'
    

    Bla.innerBla is undefined because the object (functions are objects in JavaScript) Bla does not have a member called innerBla attached to it.


    If you want to invoke it like bla.innerBla, you should do something like this:

    function bla () { /* */ }
    
    bla.innerBla = function () {
        alert("bla");
    };
    
    bla.innerBla(); 
    // will alert "bla" because the `bla` object now has a member called `innerBla`.
    

    Or you can have something like this (a pattern that I frequently use):

    function bla () {
        return {
            innerBla: function () {
                alert("bla");
            }
        };
    }
    
    bla().innerBla(); // will also alert "bla"
    

    If you want to use the constructor pattern (new), you need to do something like this:

    var bla = function () {
      this.innerBla = function () {
        alert("bla");
      };
    };
    
    var b = new bla();
    b.innerBla();
    

    This is equivalent to having a public property on an instance of an object in an OO language.


    And finally, if you want to expose innerBla by every ‘instance’ (achieved using a constructor i.e. invoking bla using the new keyword) of bla, you should add the function to bar.prototype.innerBla:

    var bla = function () { /* */ };
    bla.prototype.innerBla = function () {
      alert("bla");
    };
    
    var b1 = new bla(), 
        b2 = new bla();
    
    b1.innerBla(); // will alert "bla"
    b2.innerBla(); // will also alert "bla"
    

    This is similar to having a static method.


    On a side note, avoid naming functions with an initial capital case letter (pascal-case) because by convention, usually we only capitalize functions which need to be invoked using the new keyword (constructors).

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

Sidebar

Related Questions

Hey, I've got a question about general member function pointers. I'm trying to achieve
This question is not about timing something accurately on Windows (XP or better), but
Although I'm programming in C++, this is more of a general question about design.
Note: To clarify, the question is not about the use of the restrict keyword
This is a general question of sorts, but do you think that it's important
...meaning pattern in its general English usage, not specific to OO design patterns. Given
In general, I have the following scenario: Fetch product and its related data from
General context : MVVM application. I have a View called JobView. Its DataContext is
its out of question that a dao will not hold any state. however, for
This is a very general question but it's based on a specific problem. I've

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.