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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:48:58+00:00 2026-05-23T16:48:58+00:00

I am working on a Web chat application. The code you see above is

  • 0

I am working on a Web chat application. The code you see above is used to process data from responses received in JSON format. Basically how it works is an Ajax long-poll request is sent to the server, which pulls the messages that need to be sent to the user. Outputs in JSON format, parsed by JS, and then Minte.Processor.process(json) is called to handle the rest.

I would like to replace the switch statement with something else. As you can see there are quite a few commands (and I’m estimating at least 50 more) so I need a more elegant solution. I was thinking of creating an object that holds an array of key-value pairs where the key is the command name and value is data, but I don’t know if that is less efficient than switch.

  • 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-23T16:48:59+00:00Added an answer on May 23, 2026 at 4:48 pm

    You could create a handler object that knows how to handle each command and has a method for each one. Something roughly like:

    var myHandler = {
        addChatNotice: function(content) {
            Minte.UI.addChatNotice(content);
        }, 
    
        changeUsername: function(content) {
            Minte.Client.username = content;
        }
    
        //etc...
    };
    
    Minte.Processor.process = function(json) {
        for (var x in json) {
            var entry = json[x]; 
    
            for (var command in entry) {
                var content = entry[command];
    
                //invoke the handler function with the content
                myHandler[command](content);
            }
        }
    };
    

    Here’s a simple example: http://jsfiddle.net/XLrN5/

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

Sidebar

Related Questions

Hi everyone I am working on an Ajax web chat and this application is
So I'm working on this site web app that should let users easily chat
I need to have a working web browser in a fullscreen Direct3D application. For
We've been working on web application where in we need to implement traditional web-apps
I'm currently working on web application using VB in ASP.NET. Right now I have
I'm building a custom web chat application, and while I have the basics worked
Current Project Setup I've been working on a web-based chat, similar to Facebook chat.
I need your advice. We have an already working web resource management application, we
I'm writing web chat application, similar to GTalk. It based on Orbited + Sinatra
I'm working on a chat application which I would love to use a SQL

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.