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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:09:34+00:00 2026-05-15T22:09:34+00:00

Perhaps I am doing this wrong and suggestions on how to improve my code

  • 0

Perhaps I am doing this wrong and suggestions on how to improve my code are appreciated. My situation is this: I have a toolbar with different elements that are populated by a callback. I do not want to use the show() or hide() commands, I prefer to use detach, but I think there should be a nice way to deal with it. Here’s my code:

entryView = function _entryView() {

    var menuButton = $('<div/>').addClass('menuButton');        

    toolBar();

    $.getJSON('ajax', function(o) {
        var $enum2 = ss.IEnumerator.getEnumerator(dto.TransmittalDates);
        while ($enum2.moveNext()) {
            var dateTime = $enum2.get_current();
            $('.menu').append($('<div/>').addClass('menuitem').text(dateTime.toString()));
        }
    });
}
    toolBar = function _toolBar() {
    var flyoutMenu = $('<div/>').addClass('menu');

    $('.menuButton').click(function(o) {
          $('.menubutton').append(flyoutMenu);
    });

I did a quick cut and paste and renamed the variables to make them make sense. As you can see on the entry I build the toolbar and the very last thing I do is the ajax call. The menu, however, is not created until the “click” event, so appending is not possible.

I realize that having global variables is bad, so I’m trying to avoid that, but I think the best situation would have the ajax call populate a Menu variable and when the DOM is created, to pull from that same Menu item. How do I pull this off? Is there a better way to do it?

Edit: Fubbed a bit on the toolbar function, I think I have it should be correct now.

  • 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-15T22:09:35+00:00Added an answer on May 15, 2026 at 10:09 pm

    I’m confused by some parts of your code:

    • What’s the entryView function and when is it called?
    • Why does the toolBar function exist as opposed to being inline? From where else is it called?
    • Why are you creating functions like that? Creating a variable without var is bad practice, always makes global variables, and will be forbidden in ES5 strict mode. You should create functions like this:

      var someFunction = function(arg1, arg2) { … };
      

      or like this:

      function someFunction(arg1, arg2) { … }
      
    • Why are you giving each function a second name (e.g. _toolBar)? The “private” name will only be in scope inside the function.

    The menu doesn’t have to be in global scope, just in a scope that’s common to both functions.

    I would refactor it like this (knowing very little about the design of your application), inlining toolBar:

    function entryView() {
        var menuButton = $('<div/>' {'class': 'menuButton'}), menu = $('<div/>', {'class': 'menu'});
    
        $.getJSON('ajax', function(o) {
            var $enum2 = ss.IEnumerator.getEnumerator(dto.TransmittalDates);
            while ($enum2.moveNext()) {
                var dateTime = $enum2.get_current();
                $('.menu').append($('<div/>' {'class': 'menuItem'}).text(dateTime.toString()));
            }
        });
    
        menuButton.click(function(o) {
              menuButton.append(menu);
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Perhaps I'm doing this wrong. I want to set up a base class and
Perhaps I am doing something wrong while z-normalizing my array. Can someone take a
Perhaps any of you can help me with this anoying problem. I have long
Does anyone have a modern CSS method for doing something like this? I've been
Perhaps I am doing this incorrectly/inefficiently but this isn't working for me: $(document).ready(function(){ $('li.taglink').click(function(){
Perhaps I'm doing it wrong but I don't think WPF or GDI+ classes are
I have a situation where I'm starting a process in my code in order
Perhaps I am going about this wrong, but I am following git tutorials as
Perhaps you can help me find this in the docs. I'm using pound-quote to
Perhaps this is an effect of installing the new 4.5 beta, but my simulator

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.