0

Is there a way in JavaScript that I can override an event, but still call the original event's code? I basically want to add a single line of code to the end. So for example:

Original function

function DropDownList_OnFocus(a, b) {
    // Original Code
}

What I'd need

function DropDownList_OnFocus(a, b) {
    // Original Code
    // New Code        
}
3
  • so you want to update an event handler not the event itself? why not simply add another event handler for the same event? Commented Jan 29, 2016 at 11:44
  • Hi @gurvinder372, that's correct, however I need to ensure that the additional code is executed after the original event. I think adding another event handler could have unpredictable results in some cases. Commented Jan 29, 2016 at 11:50
  • 1
    unless your event handlers have asynch processing, they will be executed in the order of addition to the event stackoverflow.com/questions/18821625/… Commented Jan 29, 2016 at 11:52

2 Answers 2

0

Event handlers always execute sequentially in the order they were bound.

So You can simply add another event handler for the same event on the same element and put more/remaining code in the second event handler.

Sign up to request clarification or add additional context in comments.

Comments

0

I've managed to get it working using the following:

var base = DropDownList.OnFocus;
var DropDownOnFocusOverride = (function () {
    return function () {
        base();
        // Additional Code
    }
});

DropDownList.OnFocus = DropDownOnFocusOverride();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.