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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:44:53+00:00 2026-06-04T13:44:53+00:00

I am not super good with JavaScript. I am trying to write a build

  • 0

I am not super good with JavaScript. I am trying to write a build config class that can be used to set settings on the fly. The idea is to pass in the environment that it is to be run in and then the variables set up properly. I have the following:

function BuildConfig(){  
    this.build = 'html5';
    this.server = 'http://someurl',
    this.nfc = true,
    this.barcode = true,
    this.scheduler = true,
    this.getConfig = function(buildType){  

     switch(buildType)
        {
        case "ios":
            this.build = 'ios';
            this.server = 'http://someurl';
            this.nfc = true;
            this.barcode = false;
            this.scheduler = false;
            break;
        case "android":
            this.build = 'android';
            this.server = 'http://someurl';
            this.nfc = false;
            this.barcode = true;
            this.scheduler = false;
            break;
        case "websiteanonymous":
            this.build = 'websiteanonymous';
            this.server = 'http://someurl';
            this.nfc = true;
            this.barcode = false;
            this.scheduler = true;
            break;
        case "website":
            this.build = 'website';
            this.server = 'http://someurl';
            this.nfc = true;
            this.barcode = true;
            this.scheduler = false;
            break;

        default:

        }

    };  
}; 

Does this look OK? Can any improvements be made?

Thanks

  • 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-04T13:44:55+00:00Added an answer on June 4, 2026 at 1:44 pm

    Your approach is ok. And the below code is slightly shorter:

    function BuildConfig(type) {
        // Defaults
        this.build = 'html5';
        this.server = 'http://someurl';
        this.nfc = true;
        this.barcode = false;
        this.scheduler = false;
    
        switch (type) {
            case "ios":
                this.build = 'ios';
                this.scheduler = true;
                break;
    
            case "android":
                this.build = 'android';
                this.server = 'http://anotherurl';
                this.nfc = false;
                break;
    
            case "websiteanonymous":
                this.build = 'websiteanonymous';
                this.server = 'http://otherurl';
                this.barcode = true;
                break;
    
            case "website":
                this.build = 'website';
                break;
        }
    }
    
    var config = new BuildConfig('android');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have googled some time now trying to find a good sample application that
Basically is there a good elegant mechanism to emulate super with syntax that is
I posted not so long ago a class diagram for an application that I
I know that casting can really only be done from a sub class to
I know that overriding the back button functionality is not considered a good user
I've used this good tutorial to create a custom UIPopoverBackgroundView class. It works well.
I'm not super experienced in writing grammars, but let's say I have a record
I am not a fan of the following construction if (self = [super init])
Sorry this is probably super basic. But in all my javabean examples, I've not
Not sure if this counts as programming related, it's a tool that I use.

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.