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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:31:29+00:00 2026-06-10T00:31:29+00:00

I need to override (enrich) a Javascript function. Problem is the function is generated

  • 0

I need to override (enrich) a Javascript function. Problem is the function is generated automatically:

var original_function = getFunction('someID'); // eval('someID');

My code will be something like this:

var f = function(arg) { 
 do_some_stuff(); 
 original_function(arg);  
 do_another_stuff(); 
} 

And now when other part of code calls getFunction('someID') the f('someID') will be returned.

How to override the original function, when we know it’s name or we have only a function object?

  • 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-10T00:31:31+00:00Added an answer on June 10, 2026 at 12:31 am
    function someFunc (arg) { alert(arg)}
    
    
    function injectFunc(original, injection, inject_after) {
    if(typeof original === "string") original = window[original];
    return function() {
        if(!inject_after) injection.apply(this, arguments);
        var result = original.apply(this, arguments);
        if(inject_after) injection.apply(this, arguments);
        return result;
        }
    }
    
    // insert before
    someFunc = injectFunc(someFunc, function(arg) {alert("Before" + arg)});
    
    // or with string func name
    someFunc = injectFunc('someFunc', function(arg) {alert("Before" + arg)});
    
    // and after
    someFunc = injectFunc(someFunc, function(arg) {alert("After" + arg)}, true);
    
    
    // and with olny func name 
    window['someFunc'] = injectFunc('someFunc', function(arg) {alert("After" + arg)}, true);
    

    all injections are stored in function

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

Sidebar

Related Questions

I need to override a function in this file: app/code/core/Mage/Core/functions.php The problem is that
I need to override an abstract Block in Magento : app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Options/Abstract.php I need to
I need to override Backbone.sync to allow PUT the problem is i don't know
I need to override only length function from std::basic_string because it's not correct for
I need to override my form like this: protected function doSave($con = null) {
I have a function that in a different frame that I need to override.
I need to override connection between boost::signals2::signal and boost::function . For this purpose I've
I need to override default Capistrano current path. I want to deploy to /var/www/apps/myapp
I need to override the connection in my new table adapters, as they are
I need to override styles for two EditText instances. I have two issues regarding

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.