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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:58:02+00:00 2026-06-12T07:58:02+00:00

I’d like to create an event for each function in a script, then inject

  • 0

I’d like to create an event for each function in a script, then inject the event trigger into the end of the function.

This way I can see exactly when each function has completed and use the events like hooks for other functions

If I can do it dynamically, I can add as many new functions as I like without having to create and append these events.

Here’s a basic example of what I’m trying to do, this won’t actually work, but it gives you an idea. I have been using jQuery, but I’ll accept any JavaScript framework at all, and any method.

var obj = {};

(function()
{
    this.init = function()
    {
        // loop through every function
        $.each(this, function(k, v)
        {
            // create an event for every function
            $('body').bind(v, function()
            {
                 console.log('Event: ' + v + ' Finished');
            });

            // Add a event trigger into each specific function in the loop
            this[v].call($('body').trigger(v));
        });
    }
    
    this.another_function = function()
    {
        // do something
    }

    this.some_function = function()
    {
         /do something
    }

}).apply(obj);

obj.init();

(edit) The script itself basically renders a Calendar, but there are a lot of callbacks, ajax requests, buttons. etc… If I could tie each feature down to an event, it would make my life easier when extending it, adding new features etc…

  • 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-12T07:58:03+00:00Added an answer on June 12, 2026 at 7:58 am

    Loop through every function, replace it with new one, which calls original function on the same object and triggers event on body.

    var obj = { };
    
    (function()
    {
        this.init = function()
        {
            var self = this;
            foreach(var name in this) {
                if (typeof k !== 'Function') continue;
                if (name ==='init') continue;
    
                var original = this[name];
    
                var newFunc = function() {
                    original.apply(self, arguments);
                    $('body').trigger(name);
                }
    
                this[name] = newFunc;
            } 
        }
    
    this.another_function = function()
        {
            // do something
        }
    
    this.some_function = function()
        {
             /do something
        }
    
    }).apply(obj);
    
    obj.init();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words

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.