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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:59:02+00:00 2026-06-16T15:59:02+00:00

I am working on my first JS project that involves inheritance and the prototype

  • 0

I am working on my first JS project that involves inheritance and the prototype chain, and I am confused about why the creation of one object with specific data is affecting the data already in place on my second object.
The goal is to have a set of basic defaults in the full_params object literal in the “parent” object, and have some more specific defaults in the default_params object literal in the “child” object.
The child object specificRequest takes an array argument for its constructor function, adds those to its default_params, and then call the setOptions function of its prototype to add those to the full_params.

The problem is that when I create one specificRequest object and initialize it, it works fine, but then when I create a second specificRequest object, the full_params is already the same as
that of the first.

This is probably something very simple from a misunderstanding of how prototype works…

/////// PARENT OBJECT

function baseRequest(custom_params) {

    var key;

    this.full_params = {
        "SignatureVersion": "2",
        "Timestamp": Utilities.formatDate(new Date(), "GMT", "yyyy-MM-dd'T'HH:mm:ss'Z'")
    };

    this.custom_params = custom_params;

}


baseRequest.prototype.setOptions = function(arg_options) {
    var key;

    if (typeof arg_options === "object") this.custom_params = arg_options;

    // If an object of request options is passed, use that. Otherwise use whatever is already in the custom_params object.
    for (key in this.custom_params) {
        this.full_params[key] = this.custom_params[key];
    }

}





///////// CHILD OBJECT

function specificRequest(mySKUList) {
    var i;
    this.mySKUList = mySKUList;

    this.default_params = {
        "Action": "myAction",
        "Version": "2011-10-01"
    };

    for (i = 0; i < this.mySKUList.length; i++) {
        var temp_sku = this.mySKUList[i];
        var temp_sku_name = "SellerSKUList.SellerSKU." + (i + 1);
        this.default_params[temp_sku_name] = temp_sku;
    }

    this.setOptions(this.default_params);
}

specificRequest.prototype = new baseRequest






///// Function to run

function testfoo() {

    var skulist1 = ["AR6100", "AR6102", "WB1234"]
    var skulist2 = ["XY9999"]

    var req1 = new specificRequest(skulist1);
    var req2 = new specificRequest(skulist2);

    // Req1 has AR6100, AR6102, and WB1234 as parameters, as expected
    // Req2 should only have XY9999, but instead has XY9999, AR6102, and WB1234
}
  • 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-16T15:59:03+00:00Added an answer on June 16, 2026 at 3:59 pm

    Well you have tied a concrete instance of the parent class to be the prototype of the child class with this line:

    specificRequest.prototype = new baseRequest
    

    Instead, don’t instantiate the parent class at all:

    specificRequest.prototype = Object.create( baseRequest.prototype );
    

    Also, call super() equivalent when constructing a child instance:

    function specificRequest(mySKUList) {
         baseRequest.call( this );
    
         ...
    }
    

    And please start constructor names with UpperCase.

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

Sidebar

Related Questions

I am working on a project that involves a lot of data, and at
I'm working on my first Core Data project (on iPhone) and am really liking
I'm working on a project that involves parsing a large csv formatted file in
I'm currently working on a project that involves a CSV file. I initially was
I'm currently working on a project that involves moving a database of documents for
I'm currently working on a program for a uni project that involves building a
A project I'm working on at the moment involves refactoring a C# Com Object
I'm working on an iPhone project that needs to receive data from a PHP
I am working on my first asp MVC project that will ultimately end up
I'm working on a project that involves creating a spline from a defined set

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.