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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:24:30+00:00 2026-05-16T06:24:30+00:00

Suppose I had the following function: function alertMesg() { alert(This ok function alerts message!);

  • 0

Suppose I had the following function:

function alertMesg()
{
   alert("This ok function alerts message!");
}

Now at run time I would like to change the alertMesg function to do something else. My thought was to do somehting like this.

var temp = window.alertMesg.toString.replace("ok","great")
temp = temp.replace('function alertMesg()',"");
window.alertMesg = new Function(temp);

Basically, the problem is I have no control over the source in the alertMesg function. I would like to change the function, but I can’t actually change the source of it because it is produced server side. That being said, I need it to act differently.

PS: I forgot to mention an important part: I have to keep most of the function. I can’t just replace the function out right. I have to keep 95% of the function the way it is, and change the other five percent.

@Barlow Tucker, quixoto, pekka
Thanks, for the interest.

Basically, I don’t think the proxy idea will work because I am not just adding functionality, I am changing the functionality of the code. I want for example, the third line of the function to be different. In my real life example I have to add a line right in the middle of a function.

  • 1 1 Answer
  • 3 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-16T06:24:30+00:00Added an answer on May 16, 2026 at 6:24 am

    If you must replace the content of a function, it is possible:

    function alertMesg()
    {
       alert ("This ok function alerts my message!");
    }
    
    alertMesg(); // alerts "This ok function alerts my message!"
    
    // do whatever you want to the function here
    var temp = alertMesg.toString();
    temp = temp.replace('my', 'your');
    
    // now replace the original function
    alertMesg=new Function(temp.substring(temp.indexOf('{')+1,temp.lastIndexOf('}')));
    
    alertMesg(); // alerts "This ok function alerts your message!"
    

    This probably isn’t the best way to do what you’re trying to achieve, but I can’t really suggest anything else unless you provide more details.

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

Sidebar

Related Questions

Suppose you had code like this: _READERS = None _WRITERS = None def Init(num_readers,
Suppose I had the following class: class MyClass { public function Talk() { $Say
Suppose you had this: def wipeProduct(hash, nameToDelete) hash.each do |i| key = i[0] productName
Suppose I had a WCF service that I have coded up, like Clemens Vasters's
I've had trouble writing this code. I'm supposed to make a function that can
Suppose my base class is the following: function Tile(obj) { //defaults (alot of variables
Suppose I have following code: def foo(s): A dummy function foo. For example: >>>
Suppose I had the following class: template<typename T> class Value { public: Value(std::string name,
Suppose I had a MySQL table with the following column:    |variables| 1. | 'a'     | 2.
Suppose I had the following method in an object: public class foo { public

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.