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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:56:21+00:00 2026-05-29T08:56:21+00:00

Many functions in my code use this structure: options = {param1: yes, param2 :

  • 0

Many functions in my code use this structure:

options = {"param1": "yes", "param2" : "no"}

In JS I do not have to “define” this structure since it is a dynamic language.

But when I know the structure has a fixed set of fields, is it a best practice to declare it in some centralized way, just for clearness? The same goes for usage in local data members in a class. Is it a best practice to init all of them in a ctor or some other centralized way (for clearness)?

I know I could do that in comment but coming from a static language I want to know what is the javascript style.

  • 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-29T08:56:22+00:00Added an answer on May 29, 2026 at 8:56 am

    (I’m hoping you normally have a var on the front of that. 🙂 Without one, you’re falling prey to The Horror Of Implicit Globals.)

    There’s no real convention other than being clear. For me, “being clear” means a couple of things:

    1. Put all var statements at the beginning of the scope, because that’s where they really are anyway.

    2. If something has a significant structure that won’t be changing much, assign it with an object literal (as you have) as early as reasonable.

    …but “being clear” means different things to different people.

    The same goes for usage in local data members in a class. Is it a best practice to init all of them in a ctor or some other centralized way (for clearness)?

    Yes, initialize all instance-specific properties in the constructor. Properties that the object may not need its own copy of can reside on the prototype:

    function Foo(bar) {
        this.bar = bar;
        this.baz = [];
    }
    Foo.prototype.datum = 42;
    

    There, an object created via new Foo("x") will get its own property bar with the value "x", it’s own property baz with the value [], and an inherited property datum with the value 42. Putting those initializations in the constructor and on the prototype right next to it aid clarity.

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

Sidebar

Related Questions

Hey there, I have a big code file currently in C++ with many functions
I'm currently maintaining some flex code and noticed very many functions which are declared
I've tried many functions already, but I simply can't figure this out. The right
I have a class which has many small functions. By small functions, I mean
I have many structs (classes) and standalone functions that I like to compile separately
Many of the standard c library (fwrite, memset, malloc) functions have direct equivalents in
Many functions in c take pointer to constant strings/chars as parameters eg void foo(const
I'm trying to Unit Test a class that has many internal functions. These obviously
I find that many high level functions are missing in most well-known javascript libraries
In the book The C Programming Language it says: Many of the functions in

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.