简体   繁体   中英

Promise object with alerts and return values causing errors

I have an interface that I'm working on that uses javascript to override the keyboard functionality. My initial question, before going into more depth of this issue is, when an alert is called, is there a way to have functions resolve after it without it missing timing, or am I just screwed in this sense.

I have tried using the Promise object but either I am doing something wrong or this is the wrong way to do it. I can get my meta data to reset if I simply just log a response in the callback function that is passed, but if I alert it, and I would assume the same if I did an ajax call, it fails.

So that is my issue, and I'm hoping this makes sense to someone.


I will explain the interface quickly so you can understand, i apologize ahead of time for the crude list layout:

overboard

  • constructor : Overboard

    • this.handle_keydown : gets the key event and makes the magic happen
    • this.handle_keyup : get the key event on up and clears the cache essentially
    • this.listen : generates the event listeners for keyup and keydown
    • @return this
  • private : keyAction

    • the main engine of the Overboard class functionality. Checks to see if the option is set within the options object, checks for additional parameter sets, attempts the callback function, resets all meta data.

code: https://jsfiddle.net/gtqqewdd/14/


how you call the class

this is where I was running into the issue with the alert.

var override = overboard(window, {
    a : {
        ctrlKey : true,
        callback : function(k){
            if(k.ctrlKey){
                alert('ctrl+a worked');
                return true;
            }
        }
    }
});
override.listen();

If I didn't explain anything well enough or clarification is needed on something, please let me know! Thank you in advance!

Opps misread the question. You can always use a library, which will be much less error prone, something like https://dmauro.github.io/Keypress/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM