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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:09:41+00:00 2026-05-27T09:09:41+00:00

what is the difference below: function test(){ this.init=function(){//do something} this.some=function(){//do something} function other(){} }

  • 0

what is the difference below:

function test(){
    this.init=function(){//do something}
    this.some=function(){//do something}
    function other(){}
}

and

function test(){
    function init(){//do something}
    function some(){//do something}
    function other(){}

    return {'init':init, 'some':some};
}

Thanks for explanation.

  • 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-27T09:09:42+00:00Added an answer on May 27, 2026 at 9:09 am

    As Mike has already pointed out, there is a difference on how they need to be invoked (the first version requires new while the second doesn’t).

    That said, if these are being used for actual modules (instead of just objects) and the functions in the module call each other then there is a difference.

    In the second case the functions can reference each other directly (static binding).

    function init(){
        some(17);
    }
    

    But in the first case they would reference each other via dynamic binding through the this:

    this.init = function(){
        this.some(17); 
    }
    

    This means that in the first case (with the this) the init function must be always called as module.init() and cannot be passed to a callback

    setTimeout( module.init, 1000 );
    //this line will does not work with the `this.init` variation
    //but will work fine in the second version
    

    Because I don’t like having to retype the function names as in the second version, I personally prefer to use the following style in my modules:

    var module = (function(){
    
        var M = {}; //private namespace.
                    //decouples from the actual name and I
                    //can always use the same letter (for consistency)
    
        M.init = function(){
            M.some(17);
        };
    
        M.some = function(){
            //
        }
    
        function other(){ ... }
    
        return M;
    }());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a function that can return the difference between the below two dates
In the code below: (function (){ function test(){};//function var test;//undefined var printTest = typeof
EDIT: Paul has solved this one below. Thanks! I'm trying to resample (upscale) a
What is difference of below escape sequences for white space? \t, \n, \x0B, \f
Is there a difference between the two examples below for beginning a Perl script?
What's the difference between the two code below. int a[] = {0,0}; int a[2]
Is there any difference between the 2 methods below for calculating c ... specifically
Please check below screen shot. What is main difference between Master Page and MVC
When joining across tables (as in the examples below), is there an efficiency difference
I'm trying to write the VBScript equivalent of a function similar to what's below:

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.