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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:10:06+00:00 2026-05-29T10:10:06+00:00

I decided to try out JavaScript genius John Resig’s simple JavaScript inheritance as detailed

  • 0

I decided to try out JavaScript genius John Resig’s “simple JavaScript inheritance” as detailed on this blog page:

http://ejohn.org/blog/simple-javascript-inheritance/

I’m curious how one might override a method with code that calls the super method. In other words, let’s say I start with a Person class:

var Person = Class.extend({
    init: function ( name, age ) {
        this.name = name;
        this.age = age;
    }
});

I extend that Person class to create a new class Worker:

var Worker = Person.extend({
    init: function ( name, age, occupation ) {
        this.name = name;
        this.age = age;
        this.occupation = occupation;
    }
});

There’s repetition of code in the two versions of the init method. The following two lines are executed no matter which class I’m using:

this.name = name;
this.age = age;

It seems like I should be able to call the Person class’s init method from within the Hero class’s init method and then throw in the extra line of code with the occupation property.

I can’t do that with Mr. Resig’s code, though. The following doesn’t work:

var Worker = Person.extend({
    init: function ( name, age, occupation ) {
        this._super(arguments);
        this.occupation = occupation;
    }
});

As soon as the extend method called from Person to create the Worker class sees *this._super(arguments)* it replaces the entirety of Worker’s init with Person’s init leaving me with an undefined occupation property.

Does anyone have any suggestions as to how to get around this without having to modify Mr. Resig’s code? I’m currently trying out different ways to implement the concept of a “super,” but the fact that I can’t get this to work with the existing code is stuck in my head. 🙂

UPDATE: I realized that I made one small error in implementing Mr. Resig’s code which is why this behaved the way I described. @chuckj correctly pointed out an error in Worker’s init, too.

  • 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-29T10:10:08+00:00Added an answer on May 29, 2026 at 10:10 am

    Change the Worker definition to,

    var Worker = Person.extend({ 
        init: function (name, age, occupation) { 
            this._super(name, age); 
            this.occupation = occupation; 
        } 
    }); 
    

    you don’t pass the arguments array, you call the _super with the parameters it expects.

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

Sidebar

Related Questions

Got nothing better to do this Christmas holiday, so I decided to try out
I am just starting out with Python and decided to try this little project
I've stumbled upon this tutorial and decided to try it out :-). In the
After asking this question yesterday about branching in mercurial, I've decided to try out
I decided to try http://www.screwturn.eu/ wiki as a code snippet storage utility. So far
Following the advice of wcoenen, I've decided to try using registration-free COM. This works
My boss decided recently to try out an outsourcing group for increased capacity as
I recently discovered NginX, and decided to try it out on my server. I
So I decided to try out PostgreSQL instead of MySQL but I am having
I finally decided to try out Vim , as I am getting increasingly frustrated

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.