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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:25:01+00:00 2026-05-20T13:25:01+00:00

If I have an arbitrary function myFunc , what I’m aiming to do is

  • 0

If I have an arbitrary function myFunc, what I’m aiming to do is replace this function with a wrapped call that runs code before and after it executes, e.g.

// note: psuedo-javascript

var beforeExecute = function() { ... }
var afterExecute = function() { ... }

myFunc = wrap(myFunc, beforeExecute, afterExecute);

However, I don’t have an implementation of the required wrap function. Is there anything that already exists in jQuery like this (I’ve had a good look through the docs but cannot see anything)? Alternatively does anybody know of a good implementation of this because I suspect that there are a bunch of edge cases that I’ll miss if I try to write it myself?

(BTW – the reason for this is to do some automatic instrumentation of functions because we do a lot of work on closed devices where Javascript profilers etc. are not available. If there’s a better way than this then I’d appreciate answers along those lines too.)

  • 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-05-20T13:25:02+00:00Added an answer on May 20, 2026 at 1:25 pm

    Here’s a wrap function which will call the before and after functions with the exact same arguments and, if supplied, the same value for this:

    var wrap = function (functionToWrap, before, after, thisObject) {
        return function () {
            var args = Array.prototype.slice.call(arguments),
                result;
            if (before) before.apply(thisObject || this, args);
            result = functionToWrap.apply(thisObject || this, args);
            if (after) after.apply(thisObject || this, args);
            return result;
        };
    };
    
    myFunc = wrap(myFunc, beforeExecute, afterExecute);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with arbitrary columns and rows. This fact is irrelevant though
Does Java have a built-in way to escape arbitrary text so that it can
I need to be able to take an arbitrary text input that may have
I have a string of arbitrary length, and starting at position p0, I need
I have a web application where users enter arbitrary sql queries for later batch
I have a need to evaluate user-defined logical expressions of arbitrary complexity on some
I have a situation where I need to add an arbitrary unique id to
How can I have SQL repeat some set-based operation an arbitrary number of times
What is the best way to have an associative array with arbitrary value types
My particular problem: I have a string which specifies an aribitrary type in a

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.