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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:20:06+00:00 2026-06-05T04:20:06+00:00

I am trying to extend an object, and I want to modify a method

  • 0

I am trying to extend an object, and I want to modify a method of the first, not to override it. I don’t think this is clear so here is an example:

var object1 = {
    whatever : function(){
        console.log('first object method');
    }
}

var object2 = {
    whatever : function(){
        console.log('second object method');
    }
}

var object = $.extend(true, object1, object2);

object.whatever();

This example will output second object method, but what I want is that it ouput first object method and second object method.

Is there a way to do this?

  • 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-05T04:20:08+00:00Added an answer on June 5, 2026 at 4:20 am

    Javascript uses prototypal inheritance, so you can make object2 inherit object1’s properties and methods by doing

    object2.prototype=object1;
    

    this means that object2 will inherit all the properties and methods of object1, and any overwritten methods can be accessed at object2.prototype.method()

    so parent::whatever(); is equivalent to this.prototype.whatever(); when calling from the scope of object2.


    var object1 = {
        whatever : function(){
            console.log('first object method');
        }
    }
    
    var object2 = {
        whatever : function(){
            console.log('second object method');
            this.prototype.whatever(); // Equivalent to parent::whatever(); 
        }
    }
    
    object2.prototype=object1; // Makes object2 inherit object1's properties and methods
    
    object2.whatever(); // "second object method" "first object method"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to extend (not sure what is the correct term for this kind
I'm trying to extend TextBox control to add watermarking functionality. The example I've found
I'm trying to move my validations to a module. I want to extend an
Sorry my title is not great, this is my first real punt at moving
I am new to backbonejs. I am trying to pass the correct this object
I'm trying to extend a method with a single keyword argument while remaining impartial
I've been trying to extend the ArrayList class without much success. I want to
I am trying to get this jGrowl working but I am not having any
I'm trying to extend the functionality of some methods of the 2dcontext object, however
I'm trying to serve an image from a play-mini application. object App extends Application

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.