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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:00:54+00:00 2026-05-12T16:00:54+00:00

I have multiple objects in a hierarchy which have common properties and methods inherited

  • 0

I have multiple objects in a hierarchy which have common properties and methods inherited from the superclass, and object-specific properties and methods in the subclasses. I’m still new to OOP javascript, so there is probably a much better approach to this. I’m using jQuery for the AJAX, but not sure if that makes any difference.

function Obj(input) {
    this.in = input;
    this.out = {
        content: this.in,
        category: {},
        owner: utils.getValidUser(),
        state: 0,
        meta: {}
    };
    this.process = function() {
       console.log("No Process Defined");
    }
}

function MovieObj(input) {
    this.inheritFrom = Obj;
    this.inheritFrom();
    this.out.type = "movie";
}

function ActionMovie(input) {
        this.inheritFrom = MovieObj;
        this.inheritFrom();
        this.out.genre = "action";
        this.process = function() {
            console.log("movie search");
            $.getJSON("/api/search/"+ escape(this.out.content),
              function(data) {
                /* 
                   I want to modify the object properties according to
                   what comes back from the ajax call.
                */
            });
        }
}
  • 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-12T16:00:54+00:00Added an answer on May 12, 2026 at 4:00 pm

    Here is a prototypical approach to my earlier code, AND a simple reference to the calling object, which solves both the inheritance issues and the scope issues.

    // Define Superclass
    function Obj(input) {
        this.content = input;
        this.type = "object";
        this.owner = utils.getValidUser();
        this.state = 0;
    }
    Obj.prototype.process = function() {
           console.log("No Process Defined");
    };
    
    
    // Define Movie Subclass
    function MovieObj(input) {
        Obj.call(this, input); 
        this.type = "movie";
    }
    MovieObj.prototype = new Obj();
    
    // Define ActionMovie as subclass of Movie and apply new process method.
    function ActionMovie(input) {
        MovieObj.call(this, input);
        this.genre = "action";
    }
    ActionMovie.prototype = new MovieObj();
    ActionMovie.prototype.process = function() {
                var _obj = this;
                $.getJSON("/api/search/"+ escape(this.content),
                  function(data) {
                    /* 
                       I want to modify the object properties according to
                       what comes back from the ajax call.
                    */
                    _obj.meta.title data.title;
                });
            }
    }
    

    This is now actually working, but there are some caveats. As written, the constructors for the superclass are called everytime a new object is defined, so a lot of unnecessary calls are made.

    This code is based on information contained in the following link, which also describes a workaround that is Mozilla specific:
    http://www.spheredev.org/wiki/Prototypes_in_JavaScript

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

Sidebar

Related Questions

I have a group of multiple objects. If I select one object from the
I have a program in which the user adds multiple objects to a scene.
Newbie question. I have a NSMutableArray that holds multiple objects (objects that stores Bezier
Is it possible to have multiple view of the same display object? (e.g. same-computer
I have a string object with multiple characters and even special characters I am
I have a List object being accessed by multiple threads. There is mostly one
We have multiple MFC apps, which use CMutex( false, blah ), where blah allows
I have multiple classes that all derive from a base class, now some of
I have multiple business objects in my application (C#, Winforms, WinXP). When the user
Ok. I have an array with multiple objects populated by my core data stack

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.