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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:26:53+00:00 2026-05-23T05:26:53+00:00

I also have this running example on jsfiddle Sample: function Animal(o) { o.class =

  • 0

I also have this running example on jsfiddle
Sample:

function Animal(o) {
    o.class = Animal;
    o.name = o.name ? o.name : "Animal"; // Defaults
    o.age = o.age ? o.age : 0; // Defaults
    o.weight = o.weight ? o.weight : 0; // Defaults
    o.say = o.say ? o.say : "?";

    Animal.isOnEarth = true; // "static variable"

    return o;
}
function Cow(o) {
    o.class = Cow;        
    o.name = o.name ? o.name : "Cow"; // Defaults
    o.milk  = o.milk ? o.milk : 0; // Defaults
    o.say = o.say ? o.say : "MOOO";

    return Animal(o); //Inheritence
}
function Dog(o) {
    o.class = Dog;        
    o.isCrazyLab = o.isCrazyLab ? o.isCrazyLab : false;
    o.say = o.say ? o.say : "WOOF";

    return Animal(o) //Inheritence;
}

function Labradore(o) {
    o.class = Labradore;        
    o.isCrazyLab = o.isCrazyLab ? o.isCrazyLab : true;
    o.say = o.say ? o.say : "YARRWL";

    return Dog(o) //Inheritence;
}

var cow = Cow({});
var bessy = Cow({name:"bessy",milk:25});
var spot = Dog({name:"spot"});
var hugo = Labradore({name:"hugo"});

document.write("True or false, all these animals live on earth " + Animal.isOnEarth + " A cow says " + cow.say + "... bessy's name is " + bessy.name + " a " + spot.name + " says " + spot.say + " " + hugo.name + " says " + hugo.say);

I’ve got a small project that I’m working on and I wanted to implement a type of inheritance. I looked at some of the samples online but I don’t quite understand why it would be important to go through all the rigamaroll of modifying basic behaviors in javascript. To me it feels like extending the class concepts of javascript to make it “feel” like another language may save a few lines but doesn’t appear to add much core functionality. However, I am more than happy to be schooled 🙂

Some questions
Is there any libraries that work in this manner?
Any online examples of the pros and cons of doing this?
Is there a fundamental reason NOT to do this?
Any general thoughts?

  • 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-23T05:26:54+00:00Added an answer on May 23, 2026 at 5:26 am

    That’s not really inheritance, it’s basically copying. Not that terminology necessarily matters here. 🙂

    The main downsides I see are:

    • instanceof won’t work
    • You lose out on the mechanisms JavaScript provides for sharing resources across implementations (the prototype chain).
    • It’s surprising, at odds with other objects defined in the language. I don’t expect to always have to pass an object into constructors, and I expect to use new with them.
    • No clear way to call a “super”‘s version of a function.

    Off-topic: A couple of notes:

    • class is a reserved word in JavaScript. You shouldn’t use it as an identifier, just as you wouldn’t use for or if as an identifier.
    • You can simplify a bit by using the curiously-powerful || operator, e.g.:

      o.name = o.name || "Cow"; // Defaults
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have my website running at: www.example.com I also have this other domain: www.example.net
I have a listener like this: $('.delete').click(function() { ...some stuff }); Also, on the
I have this situation: application server running on example.com - this is where html
I have this webserver that have an IP address xxx.xxx.xx.x, I also have a
[I have posted this at the Django users | Google Groups also.] Using the
I have strings like this: Car is blue String could also be like this:
I have a CSS image sprite and this renderes perfect in FF, also IE.
This doesn't have to be Java, but it's what I'm dealing with. Also, not
I have created a reddot cms component, in which I added this line Also,
what I have is the currencyIsoCode EUR. This Property can also be found in

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.