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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:05:02+00:00 2026-06-08T01:05:02+00:00

As of now, I’ve been using self-executing anonymous functions in order to avoid having

  • 0

As of now, I’ve been using self-executing anonymous functions in order to avoid having variable naming issues:

(function () {
    var a, b, c;
    a = 5;
    b = 10;
    c = 15;
    console.log('No problema!');
]());

I also know that using the onload function is also an alternative approach:

window.onload = function () {
    var a;
    a = 25;
    console.log('Yay!!!');
}

But I really dislike how my code is completely trapped inside a function – is there an approach that I could take with JavaScript objects that could help me avoid using self-executing functions?

  • 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-08T01:05:03+00:00Added an answer on June 8, 2026 at 1:05 am

    On most of today’s browsers, functions simply are the unit of encapsulation. If you want to create a scope for a variable, you make it local to a function.

    But today with many server side JavaScript installations, modules exist, many based on require.js. If you write apps with Nodejs, you’ll be familiar with it already.

    The next version of JavaScript is coming soon, though. Named ES6, ES.next, Harmony, or JavaScript.next, this new JavaScript will have modules for your information hiding, as well as block scope. Many browsers are starting to implement features of the language now. You can experiment with in at http://repl.it, among other places. You can use Google’s Traceur compiler to compile a language including many of the ES6 proposals into today’s JavaScript.

    TL;DR: for now: stick with functions in the browser. Or use require.js for your server side applications. Hang on because ES6 is coming.

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

Sidebar

Related Questions

Now I am using the following function to secure my strings : function secure($data)
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Now I have learnt a little bit of assembler (using NASM) I want to
Now I am using the devise gem, and after successful authorization it redirects user
Now I've been trying to create a similar functionality as there is in Push-To-Talk
Now that .NET v3.5 SP1 has been released (along with VS2008 SP1), we now
Now I'm using iTunes to convert .mid file to .wav file, I wonder if
Now a Days I get Data using service that is converted to JSON Data
Now i know there have been a lot of question about this, but i

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.