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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:36:03+00:00 2026-06-12T02:36:03+00:00

EDIT Let me get more to the point. I’m trying to create a psuedo

  • 0

EDIT

Let me get more to the point. I’m trying to create a psuedo promise implementation. The idea here being that I have a callback that won’t be executed until an asynchronous call is received. So I’m simply queueing up all the calls to this function until the time at which it’s notified that it can be executed. The queue is emptied and any further call to the function is SUPPOSED to execute immediately, but for some reason, the function is still queueing. This is because, for whatever reason, my redefinition of the runner function is not working correctly. The code below was my sleep deprived, frustrated version of every thought that went through my head. Here’s the actual code:

function Promise(callback){
  var queue    = []
    , callback = callback
    , runner   = function(){
        queue.push({
          context: this,
          args: Array.prototype.slice.call(arguments, 0)
        });
      }
  ;//var

  runner.exec = function(){
    for(var i = 0, ilen = queue.length; i < ilen; i++){
      var q = queue[i];

      callback.apply(q.context, q.args);
    }

    runner = callback;
  };

  return runner;
}

test = Promise(function(){
  $('<div/>').appendTo('#output').html(Array.prototype.slice.call(arguments,0).toString());
});

test(1,2);
test(3,4);
test.exec();
test(5,6);​

http://jsfiddle.net/a7gaR/


I’m banging my head against the wall with this one. I’m trying to reassign variables in a function from a call outside the function itself (ideally by passing a reassignment function as a callback). In the example I posted on jsfiddle, I made a global function that, in theory, has a reference to the variables contained within its parent function. Upon calling that external function, I expect it to reassign the values that the other function is using. It doesn’t seem to work this way.

window.test = function temp() {
    var val = 7,
        func = function() {
            return val;
        };

    window.change = function() {
        window.test.val = 555555;
        $('<div>Changing ' + val + ' to ' + window.test.val + 
               '</div>').appendTo($output);
        val = window.test.val;
        temp.val = window.test.val;
        func = function() {
            return 'Why isn\'t this working?';
        }
    }

    return func();
}

var $output = $('#output');

$('<div/>').appendTo($output).html('::' + test() + '::');
window.change();
$('<div/>').appendTo($output).html('::' + test() + '::');

http://jsfiddle.net/YhyMK/

  • 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-12T02:36:04+00:00Added an answer on June 12, 2026 at 2:36 am

    I finally created a function that would perform this operation. The gist for it is here: https://gist.github.com/2586972.

    It works like this…

    You make a call to Defer passing the callback whose functionality you’d like to delay:

    var deferredCB = Defer(function(){ console.log(this,arguments) };
    

    deferredCB will now store all of the arguments you pass allowing them to be executed at some later date:

    defferedCB(1);
    defferedCB(2);
    

    Now, when you’re ready to perform the operation, you simply “execute” deferredCB:

    defferedCB.exec();
    

    Which results in:

    // window, 1
    // window, 2
    

    All future calls to deferredCB will be executed immediately. And now that I’m thinking about it, I’ll probably do a rewrite to allow you to reset deferredCB to it’s pre-executed state (storing all the arguments again).

    The key to making it work was having a wrapper function. Javascript simply won’t let you reassign a function while it’s being executed.

    TADA!!!

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

Sidebar

Related Questions

I'm using a CMS that doesn't let me edit the HTML, I can only
Edit 2: Actually SomeEventHandler is more concise than OnSomeEventHandler : If I let Visual
Please let me know if you have any idea about it. Thanks EDIT What
EDIT: You can see the search box live here . Before I explain, let
Strange one here, hoping to get some feedback to point me in the right
EDIT To make this post a bit more constructive, and let it possibly help
I am trying to allow a User to remove a point (or more specifically,
In PHP I am going to edit some entity let say a project named:
EDIT To simplify this further. Let's take a look at this structure: Table1: idProduct
So. Let's say I were to make a hex editor to edit... oh... let's

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.