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

The Archive Base Latest Questions

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

Is it possible to override the call function on a generic level, so that

  • 0

Is it possible to override the “call” function on a generic level, so that every time when a method gets called anywhere in the app, something happens.

I tried overriding Object.call, but although I managed to do it, it didn’t change anything in the way my app works.

BTW, even if it works, should I explicitly call “foo.call(this,args)” every time, or normal function calls will also work “foo(args)” ?

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

    Sounds like you want to do some kind of aspect oriented programming here….

    JavaScript, as an ECMAScript dialect, does have the notion of a callable object. Every callable object has an internal property called [[Call]]. This property is described in Section 8.6.2, Table 9, of the ECMA-262 Specification, 5th edition. It says:

    Executes code associated with the object. Invoked via a function call expression. The arguments to the SpecOp are a this object and a list containing the arguments passed to the function call expression. Objects that implement this internal method are callable. Only callable objects that are host objects may return Reference values.

    But the thing to be aware of is that [[Call]] is an internal property, for which the spec says:

    An internal property has no name and is not directly accessible via ECMAScript language operators. Internal properties exist purely for specification purposes.

    So you can not hook into this mechanism in your own JavaScript code.

    Now there are two methods defined in Function.prototype, apply and call. It is true that if you change the definition of Function.prototype.call then if you create your own function f, then f.call will indeed (unless overridden in f’s prototype or in f itself) execute that code. This will, as you presumed, NOT automatically happen by calling f directly. You have to explicitly call the call method.

    All that said, it is best not to muck with predefined, standard methods in the prototypes of built-in objects. A lot of existing code in libraries and applications depend on Function.prototype.call. Don’t mess with it. You can, of course, implement a kind of AOP behavior in many ways. One is to add to Function.prototype some other method, but don’t do this either. Another is to write your own call method with before and after hooks:

    function call(theThis, before, main, after, beforeArgs, mainArgs, afterArgs) {
        before.apply(theThis, beforeArgs);
        main.apply(theThis, mainArgs);
        after.apply(theThis. afterArgs);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to override a generisized function as illustrated in the code snippet
It is possible in plain Java to override a method of a class programmatically
I want to override the Tostring() method for changing some characters. Is it possible?
In C# it is not possible to override a static method. Nevertheless I have
Using Windows Detours in C++, I've seen that it is possible to trampoline function
Is it possible in C++ to have a class override a virtual function, but
It's possible to specify a particular function to be called when button is clicked
Is it possible to override default value of WebClientProtocol.Timeout property via web.config? <httpRuntime executionTimeout=500
Is it possible to override the background color of the minimize and maximized buttons
Is it possible to override reflection functionality ?

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.