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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:05:19+00:00 2026-06-03T05:05:19+00:00

I am thinking about the correct programming approach: As I write my JavaScript code,

  • 0

I am thinking about the correct programming approach:

As I write my JavaScript code, I refer to many dynamically created global objects and variables from within my functions and objects, although I did not pass them as function arguments. This way, I am losing function versatility and independence, as the functions and objects depend on another global objects in my application. I am aware of this fact, however, my objects/functions often need many variables to work with.

Would you advice, whether I should always strive to pass all the variables and objects as function arguments? This way it will be clear, what variables the function needs, and if I supply the correct arguments, the function will always work

Alternatively, don’t I need to be so strict, and as long as my functions/object work, despite they refer to global objects, do not I need to bother with this question anymore?

I need to know correct programming approach, so I do not get used to wrong things.

  • 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-03T05:05:21+00:00Added an answer on June 3, 2026 at 5:05 am

    Yes you want to use global variables as little as possible. If as a result you find that you’re passing a lot of parameters into each function then you should look at the parameters and ask what they have in common. Quite often, adding additional objects helps. You can combine parameters into instance variables of an object and pass the one object. Then, rather than extracting the instance variables, you delegate operations to that object.

    For example, suppose you have the following code:

        drawLine(fromX, fromY, toX, toY, thickness, color, canvas)
    

    You can create a Point to hold the x,y values and a graphics context to hold the thickness, color and canvas. The resulting call becomes:

        drawLine(from, to, context)
    

    You’ve reduced the number of parameters and created reusable objects that contain commonly used operations.

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

Sidebar

Related Questions

I am writing custom form validation javascript library and I am thinking about correct
I was thinking about system calls and code that we write! Lets say I
Thinking about avoiding code replication, I got a question that catches me every time
I was thinking about my code, and I accidentally clicked the Ln 74 at
I was thinking about a code that I wrote a few years ago in
I've been thinking about what I would miss in porting some Python code to
Thinking about if we modify the definition of Hamiltonian path as we need to
Been thinking about this for hours now. Im building a simple slideshow application, where
Just thinking about the best way to build an Order form that would (from
Im thinking about learn to develop app for iOS. I had a lot of

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.