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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:10:36+00:00 2026-05-29T04:10:36+00:00

I made code like this, to easier connecting callbacks on events: dojo.ready(function() { for(var

  • 0

I made code like this, to easier connecting callbacks on events:

dojo.ready(function() {
    for(var action in page.actions) {
        for(var key in page.actions[action]) {
            (function() {
                dojo.query(key).connect(action, function(evt) {
                    if(page.actions[action][key]() == false) 
                        dojo.stopEvent(evt); 
                });
            })();
        }
    }
});

page = {
    actions : 
    {
        onclick : 
        {
            "#page-action-one" : function()
            {
                alert("Action 1");
                return false;
            },
            "#page-action-two" : function()
            {
                alert("Action 2");
                return false;
            }
        }
    }
};

But click on “#page-action-one” an “#page-action-two” make the same alert(“Action 2”). I tried to use cloer, but without effect. I now, I can make it different way, but I would like to now, why is this happening.

  • 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-29T04:10:38+00:00Added an answer on May 29, 2026 at 4:10 am

    You’re trying to fix the closure issue by wrapping your event handler assignment in an anonymous function. But the key to that trick is that you have to pass in the looping variable (or variables) as an argument to the anonymous function – otherwise the anonymous function wrapper does nothing. Try:

    dojo.ready(function() {
        for(var action in page.actions) {
            for(var key in page.actions[action]) {
                (function(action, key) {
                    dojo.query(key).connect(action, function(evt) {
                        if(page.actions[action][key]() == false) 
                            dojo.stopEvent(evt); 
                    });
                })(action, key);
            }
        }
    });
    

    This “fixes” the value of action and key at the time the anonymous function is called, so within the anonymous function those variable names only apply to the passed arguments, not to the named variables in the outer scope, which will update on the next loop iteration.

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

Sidebar

Related Questions

Often I see code like this scattered and duplicated around source code: var handler
I've made some experimental code that I would like to save in the repository,
I made this code with jQuery to fade images ( but not the one
I am pretty new at C# and .NET, but I've made this code to
Long story short Say I have the following code: // a class like this
I was using code like this: handler.Invoke(sender, e); But the problem with that code
I made a code that translate strings to match each word from the array
I made some code, for understanding the concept/basic of pointer: int a=1; int *b=&a;
I have made some code which exports some details of a journal article to
now i made JavaScript code (jquery code) and when i click ok it return

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.