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

Ask A Question

Stats

  • Questions 192k
  • Answers 192k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Ideally you want to avoid allowing the browser to resize… May 12, 2026 at 6:27 pm
  • Editorial Team
    Editorial Team added an answer You have some quite specific requirements that don't appear to… May 12, 2026 at 6:27 pm
  • Editorial Team
    Editorial Team added an answer EDITED ANSWER: This doesn't seem appropriate for lookbehind. Why don't… May 12, 2026 at 6:27 pm

Related Questions

I have a non document-based Core Data application. There's an NSTreeController that manages a
I'm somewhat new to the ASP.NET MVC architecture and I'm trying to sort out
I have 3 kinds of objects: Agency, BusinessUnit and Client (each with their own
I'm working on a .NET project that integrates with an external company. This company
I have written a custom server control which (pseudo-code) looks like public class MyCustomCtrl

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.