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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:41:09+00:00 2026-05-27T19:41:09+00:00

Hullo! This is my first question! I am experimenting with the module pattern promoted

  • 0

Hullo! This is my first question!

I am experimenting with the module pattern promoted by Doug Crockford and others. Mostly very happy with it so far, but I am a little unsure about the best way of handling a certain inheritance pattern.

I have it boiled down to a bare bones case using cat and mammal, although my actual intention is to make objects for a tile based game in canvas.

But here is my bare bones ‘animals’ case using a browser alert:

var ZOO = ZOO || {};
//
ZOO.mammal = function () {
   "use strict";
   var voice = "squeak.mp3", // default mammal sound
      utter = function () {
         window.alert(this.voice);
      };
//
   // public interface
   return {
      utter: utter,
      voice: voice
   };
};
//
ZOO.cat = function () {
   "use strict";
   // hook up ancestor
   var thisCat = ZOO.mammal();
   thisCat.voice = "miaw.mp3";
   return thisCat;
};
//
var felix = ZOO.cat();
felix.utter();

What bothers me about this approach is that I have had to make voice a public property so that cat can modify it.

What I really want is something like ‘protected’ visibility (from Java, ActionScript etc.), so that cat can modify voice without anyone with access to felix being able to modify it.

Is there a solution?

  • 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-27T19:41:09+00:00Added an answer on May 27, 2026 at 7:41 pm

    You can simulate protected visibility (visible to yourself, and child objects) by passing a blank object to your base “class” to serve as the repository for your protected properties. This will allow you to share properties through your inheritance chain, without making them public.

    var ZOO = ZOO || {};
    
    ZOO.mammal = function (protectedInfo) {
       "use strict";
       protectedInfo = protectedInfo || {};
       protectedInfo.voice = "squeak.mp3";
    
       // public interface
       return {
          utter: function () {
             alert(protectedInfo.voice);
          }
       };
    };
    
    ZOO.cat = function () {
       "use strict";
    
       var protectedInfo = {};
       // hook up ancestor
       var thisCat = ZOO.mammal(protectedInfo);
    
       protectedInfo.voice = "miaw.mp3";
       return thisCat;
    };
    

    Here’s a live demo

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

Sidebar

Related Questions

Hello this is may first question and I have found so far the following
First off - hello, this is my first Stack Overflow question so I'll try
First : Appologize for my bad english. Sorry for this newbie software question, but
Preamble So, this question has already been answered, but as it was my first
this my first question! I am playing around with the Google slide template that
This is my first post. Please forgive me for asking a basic question as
this is my first time on this forum, so forgive me if my question
this is my first question and I've been messing around with android for just
This is, hopefully, a simple question: First, I would like to know if anyone
This is the first time i'm asking a question here at stack overflow so

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.