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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:23:12+00:00 2026-05-24T20:23:12+00:00

when creating an object I wish to extend the functionality of an existent prototype

  • 0

when creating an object I wish to extend the functionality of an existent prototype function with a new function. the new function needs to call the original prototype function to perform, but they are apparently in the same namespace.

Obj = function(i,newFn) {
   this.i = i;
   if( newFn ) this.fn = newFn;
}
Obj.prototype.fn = function(a) { return a+this.i; }

o1 = new Obj1( 3, function(a) { if( a<0 ) return 0; return ORIGINAL.fn(a) } );

if ORIGINAL is this.fn then o1.fn becomes non-terminating recursive

how do I reference Obj.prototype.fn() from within o1.fn()?


answer, as per @PeterOlsen,

o1 = new Obj1( 3, function(a) { return Obj.prototype.fn.call(this,a) } );
  • 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-24T20:23:14+00:00Added an answer on May 24, 2026 at 8:23 pm

    You should be able to get there, you just might have to go a little farther than you expected. Try something like

    Obj = function(i,newFn) {
       this.i = i;
       if( newFn ) this.fn = newFn;
    }
    Obj.prototype.fn = function(a) { return a+this.i; }
    
    o1 = new Obj( 3, function(a) { if( a<0 ) return 0; return this.constructor.prototype.fn.apply(this, arguments) } );
    

    In your closure, get the prototype for the constructor that was used to make this object, and then use .apply() to invoke the instance method you want using this and the arguments you passed in.

    Or like Peter Olson said, instead of this.constructor.prototype.fn you can use Obj.prototype.fn, but you still need to use either .call() or .apply(), to make sure that you execute the method in the right scope, otherwise this wont point to what you think it should.

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

Sidebar

Related Questions

I am creating object-detection program on Mac. I want to use iSight in manual
I have astring directly coming form the database and I am creating object of
Does creating an object using reflection rather than calling the class constructor result in
Below I am creating an object in JavaScript. Within the constructor I am setting
I am creating an object which tracks changes (Updates) regarding the creation, updating and
I did it by creating OLE object with Delphi in 2000/NT/XP as following: Voice
Firefox 3.5 does not allow creating java OBJECT tag with Javascript (document.write)? this technique
On application start I'm creating Config object (Singleton). How could I make Config object
I have a couple questions about creating a object (2 values) and how to
Hello can anybody solve this please I'm creating the object in the action class

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.