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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:26:45+00:00 2026-05-24T07:26:45+00:00

So i’m setting up an object with private and public methods. Basically using the

  • 0

So i’m setting up an object with private and public methods. Basically using the following format:

var Utility = function() {
    var prive1, priv2, priv3;
    function privateMethod1() { //do something }

    return {
        publicFunc1: function() { //do something different }
        publicFunc2: function() { //do something else }
    }
}

But i’m worried about some of the situations i’m coming across where publicFunc2 needs to call publicFunc1. For Example the way I would do this atm is:

publicFunc2: function() { Utility.publicFunc1(); //then do something else }

is this OK? It runs, but it seems weird and VS2010 doesn’t give me . I believe that if someone was to change the line
var Utility = function() { –> to –> var Utility2 = function() {}
then essentially everything would be broken from within the object and that seems wrong…
but i’m at a loss on what i should actually be changing.
Should i be making all methods basically private and then mapping to a public function? EX:

{
    function privateFunc1() {}

    return {
        publicFunc1 : privatefunc1
    }
}

or should i have a completely different approach to accomplish the idea of private and public methods and variables?

  • 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-24T07:26:46+00:00Added an answer on May 24, 2026 at 7:26 am

    If you want to call some function – give it a name and call it by that name:

    var Utility = function() {
        var prive1, priv2, priv3;
        function privateMethod1() { //do something }
    
        function Func1() { //do something different }
        function Func2() { Func1(); //do something else }
    
        return {
            publicFunc1: Func1,
            publicFunc2: Func2
        };
    }
    

    Call of local function by name is always faster than any other method of call in JS.

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

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim

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.