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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:15:29+00:00 2026-05-25T20:15:29+00:00

Granted I’m a javascript noob (at best). The following code seems to work fine.

  • 0

Granted I’m a javascript noob (at best). The following code seems to work fine. Any ideas how to keep the same “initializer” approach and make it work without using __proto__ and without converting everything to constructor functions?

var Employee =
    {
    paygrade: 1,
    name: "",
    dept: "general",

    init: function()
        {
        return this;
        },

    salary: function()
        {
        return this.paygrade * 30000;
        }
    };



var WorkerBee =
    {
    paygrade: 2,
    projects: ["Project1", "Project2"],

    init: function()
        {
        this.__proto__ = Inherit_Employee;  // Inherit My Employee "Pseudo Prototype"
        return this;
        }
    };


var SalesPerson =
    {
    dept: "Sales",
    quota: 100,

    init: function()
        {
        this.__proto__ = Inherit_WorkerBee; // Inherit My WorkerBee "Pseudo Prototype"
        return this;
        }
    };


var Engineer =
    {
    dept: "Engineering",
    machine: "im the start machine",

    init: function()
        {
        this.__proto__ = Inherit_WorkerBee; // Inherit My WorkerBee "Pseudo Prototype"
        return this;
        }
    };


var Inherit_Employee = Object.create(Employee).init();      // Create My Employee Pseudo-Prototype
var Inherit_WorkerBee = Object.create(WorkerBee).init();    // Create My WorkerBee Pseudo-Prototype


var jane = Object.create(Engineer).init();
var jill = Object.create(Engineer).init();

I do have one approach that works, but I’m wondering if there is a more efficient approach. For now, what I have done is replace the lines that reference __proto__ with a call to my own inheritence function like this.

    init: function()
        {
        inherit(this, WorkerBee);   // Inherit WorkerBee
        return this;
        }

And this is my inherit() function

function inherit( childObject, parentObject )
    {
    // childObject inherits all of parentObjects properties
    //
    for (var attrname in parentObject)
        if ( childObject[attrname] == undefined )
            childObject[attrname] = parentObject[attrname];

    // childObject runs parentObject 'init' function on itself
    //
    for (var attrname in parentObject)
        if ( typeof parentObject[attrname] == "function" )
            if ( attrname == 'init' )
                parentObject[attrname].call(childObject);
    }
  • 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-25T20:15:29+00:00Added an answer on May 25, 2026 at 8:15 pm

    Why you dont use standard javascript function inheritance? For example:

    function inherit(childClass, parentClass) {
        var f = function() {}; // defining temp empty function
        f.prototype = parentClass.prototype;
        f.prototype.constructor = f;
    
        childClass.prototype = new f;
    
        childClass.prototype.constructor = childClass; // restoring proper constructor for child class
        parentClass.prototype.constructor = parentClass; // restoring proper constructor for parent class
    }
    
    
    Employee = function Employee( /*list of constructor parameters, if needed*/ ) {}
    Employee.prototype.paygrade = 1;
    Employee.prototype.name = "";
    Employee.prototype.dept = "general";
    Employee.prototype.salary = function() {
        return this.paygrade * 30000;
    }
    
    
    WorkerBee = function WorkerBee( /*list of constructor parameters, if needed*/ ) {
        this.projects = ["Project1", "Project2"];
    }
    inherit(WorkerBee, Employee); // for this implementation of *inherit* must be placed just after defining constructor
    WorkerBee.prototype.paygrade = 2;
    WorkerBee.prototype.projects = null; // only literals and function-methods can properly initialized for instances with prototype
    
    
    Engineer = function Engineer( /*list of constructor parameters, if needed*/ ) {}
    inherit(Engineer, WorkerBee);
    Engineer.prototype.dept = "Programming";
    Engineer.prototype.language = "Objective-C";
    
    var jane = new Engineer( /*Engineer parameters if needed*/ );
    var jill = new Engineer( /*Engineer parameters if needed*/ );
    var cow = new Employee( /*Employee parameters if needed*/ );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to fo the following: Check if Public or guest is granted any
According to select name from system_privilege_map System has been granted: SELECT ANY TABLE ...and
Granted he didn't show us actual code here, just mentioned it, I found it
I have two images like so. (granted that the code is indented) @Html.Image(/Images/icons/arrow-up.gif, up)
I am writing an android application to which I have granted the following privileges
I am experiencing some pretty weird output from some c code. Granted I am
i created the following ActionFilterAttribute to check if a user is granted access to
This is going to sound silly, because everyone seems to take it for granted
While working within C++ libraries, I've noticed that I am not granted any intellisense
Granted... this is a dumb question, but it's still a mystery to someone like

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.