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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:34:09+00:00 2026-06-09T06:34:09+00:00

I want to make simple classic inheritance with JavaScript. I just need sub classing

  • 0

I want to make simple classic inheritance with JavaScript. I just need sub classing and method overriding and not the verbose syntax and bells and whistles as provided by prototype.js or some of the other libraries.

Now, this fellow named Shelby S. Moore has come up with a solution that works just the way I want it to:
http://www.coolpage.com/developer/javascript/Correct%20OOP%20for%20Javascript.html

Only problem is that he is extending native types Object and Function which breaks some of the libraries I use. Also as a general observation I don’t want to mess with the prototypes of native objects.

I’ve made Shelby S. Moore’s example live here:
http://jsfiddle.net/christian1974/CEKL5/

As you can see from the example it works as expected.
Now, the $64.000 question is: Can you recommend a way of making it work without messing with Object.prototype and Function.prototype?

I was looking for a really simple syntax like:

Extend(parent, this);

Should I just drop the whole idea and go with an existing library that does this? Am I making life too difficult for my self?

  • 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-06-09T06:34:11+00:00Added an answer on June 9, 2026 at 6:34 am

    Why not, instead of augmenting the object prototype, just create a function inherits?

    function inherits(parent)
    {
        //just make sure this doesn't get called on the global object (like a regular function)
        //and the parent is an actual constructor reference
        if (this === window || typeof parent !== 'function')
        {
            throw new Error('inherit not possible on window/without constructor');
        }
        //to set the constructor dynamically and secure the constructor of child object
        //I'd say this should do the trick (be weary though, not tested)
        var constr, Proto;
        constr = this.constructor;
        Proto = typeof parent === 'function' ? new parent : parent;//get instance
        this.prototype = Proto.prototype;
        this.constructor = constr;//restore constructor when needed
        if( arguments.length > 1 )
        {
            return parent.apply( this, Array.prototype.slice.call( arguments, 1 ) );
        }
        return parent.call( this );
    }
    
    function Foo(someArg)
    {
        inherits.apply(this,[Bar,someArg]);
    }
    

    That being said, I don’t really see the benefits of this method over, say, Object.create and -since you’re using libs- jQuery’s .extend method

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

Sidebar

Related Questions

I need information about making installation packages for Linux. I want to make simple
I want to make a simple just-in-time compiler with c on Linux. How can
Just want to make simple extension for syntactic sygar : public static bool IsNotEmpty(this
I want to make a simple FORM (not SQLFORM) in web2py with two fields
I want to make a simple thinge. Just a text with underline line like
I want to make a simple login page, without register just a username and
I want to make a simple image viewing program, that just takes the images
I want to make a simple user notification in rails with just text. I
I want to make a simple 2d terrain with just a few bumps and
Basically I want to make simple toggle program (that will be mapped to some

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.