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

  • Home
  • SEARCH
  • 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 6712769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:17:55+00:00 2026-05-26T08:17:55+00:00

I have this object var X = { a:function(args){ }, b:function(args){ }, c: ……

  • 0

I have this object

var X = {
   a:function(args){
    },
   b:function(args){
    },
   c: ...... etc
}

X.a() // will do somthing

I want to modify the method that it will do one more statement say “counter++”

So

var oldX = X.a();
X.a =function(args){
       oldX(args);
        counter++;
}

if i want to make this change to all the methods of the object X . So how can i do this by looping through the object like?

for(var i in X){

}

when i tried it by storing in an ooldArray of methods but while executing it will replace all the method with lastone ..

  • 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-26T08:17:55+00:00Added an answer on May 26, 2026 at 8:17 am

    I’m completely sure the behavior you want should be achieved using prototypical inheritance. But I’m know nothing about your architecture and requirements, so here is the solution written in the way you want:

    var x = {
           a: function(){
               console.log('x.a')
           }, 
           b: function(){
               console.log('x.b')
           }
        },
        oldx = {},
        key;
    
    for (key in x) {
        oldx[key] = x[key];
        (function(key){
            x[key] = function(){
                oldx[key].apply(this, arguments);
                console.log('x.new_'+key);
            }
        })(key);
    
    }
    
    x.a();
    x.b();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that returns this object: var result = AjaxUserToPlacePaging(); //this is
I have a javascript that does this (http is your XMLHttpRequest object) var r
I have a LINQ query that returns some object like this... var query =
I have this code: $('.be-delete').live('click', function(e){ e.preventDefault(); var object =$(this); var url = $(this).attr('href');
Suppose I have this code: var myArray = new Object(); myArray["firstname"] = "Bob"; myArray["lastname"]
I have this object graph, I want to map: abstract Account (username, password, ...)
I have this object which is an instance of a superclass. I want to
I want to understand about variables, that has been used in returning function. This
I have this object: var count = { table: 15, people: 34, places_details: 85,
I have this JS function : var i = 0; for (i = 0;

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.