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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:07:02+00:00 2026-05-24T21:07:02+00:00

I started to learn JavaScript, after years of using it without really knowing what’s

  • 0

I started to learn JavaScript, after years of using it without really knowing what’s going on, i decided it is time to do something about that. Additionally, I work on a project where JavaScripts can be used to script the Application.

So, enough of all the yada-yada, my problem relates to prototypal inheritance, I think I know how it works by now, but there might be issues. The basic Idea is that every object (well, not every object – yeah ;-)) has a prototype where all requests are delegated to if the actual object cannot handle it until the end of the prototype chain has been reached (the prototype of an object can have a prototype too, right?).

In my Application, massive filtering is going to happen and I want to give the users (which are not very technical, It should be as easy as possible.) a way to chain simple filter commands narrowing the result set with each additional call. What do I mean? Smth. like this:

zoo.getAnimals().getAnimalsWithFurColor("red").getMammals()

zoo is always in scope and is an object containing animals and additional properties for the zoo. So, I would have an object like this (lets call it Container) to be returned by all method calls in the example:

 {
   data: [harryTheElephant, sallyThePenguin, timTheWoodpecker],
   someFilterMethod: function() {
        return new Container(data.filter(function(animal) {
            return animal.someProperty == someValue;
        });
   }
 }

So far, so good. But i want the Zoo to be a container too. This is where my real question comes into play: As the zoo has to do some very expensive stuff to retrieve the starting set of animals, i want to lazy-load them. When the zoo gets an getAnimals()
request the data is fetched.

My Idea was to set the prototype of the Zoo to be a Container which obtains its data from the zoo. But I cannot find a way to access the getAnimals() method from the zoo from the prototype (the container). I tried it with this but the method cannot be found.

Any Ideas how to write code that does what i want to do? Please note that i’m not in a Browser environment, i embed JavaScript (1.7) in my Application.

Thanks!

  • 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-24T21:07:03+00:00Added an answer on May 24, 2026 at 9:07 pm

    It doesn’t make much sense for an object to access the properties of something that (prototypally) inherits from it. E.g., if a Cat has a meow() method, it would be weird for Mammal to reference meow(). Similarly, it would be weird for Container to reference getAnimals(), if Zoo is the one deriving from Container.

    My suggestion, to accomplish your lazy-loading, would be to pass an accessor function that returns an array into the Container constructor, instead of passing an array directly. This might look something like:

    function Container(getAnimals) {
        this.someFilterMethod = function () {
            return new Container(function () {
                return getAnimals().filter(function (animal) {
                     return animal.someProperty === someValue;
                });
            });
        };
    
        this.get = getAnimals;
    }
    
    function makeZoo(animals) {
        var zoo = Object.create(new Container(function () { return animals; }));
        zoo.customZooMethod = function () { /* ... */ };
    
        return zoo;
    }
    
    var aZoo = makeZoo([harryTheElephant, sallyThePenguin, timTheWoodpecker]);
    var filteredAnimals = aZoo.someFilterMethod().get();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After trying to avoid JavaScript for years, Iv started using Query for validation in
I started to learn using Instrument, but I cannot figure it out. After I
I recently started to learn about LINQ and came across the OrderBy extension method.
I've just started to learn about tie . I have a class named Link
I've started to learn how to use the CakePHP framework for a part time
I've just started to learn C (using Thinking In C ) and I'm wondering
I have recently started to learn Objective-C and write my tests using OCUnit that
I have started to learn about python and is currently reading through a script
I started to learn everything connected with Azure platform a little time ago. I'm
I just started to learn jquery and JavaScript so i can implement it with

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.