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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:32:55+00:00 2026-06-10T14:32:55+00:00

I was reading Introduction to Object-Oriented JavaScript from Mozilla Developer Network, time to learn

  • 0

I was reading Introduction to Object-Oriented JavaScript from Mozilla Developer Network, time to learn so serious Javascript before start using node.js.

Anyway, inheritance thing seems so obscure to me. Copy and paste from the documentation:

// define the Person Class
function Person() {}

Person.prototype.walk = function(){
  alert ('I am walking!');
};
Person.prototype.sayHello = function(){
  alert ('hello');
};

This is easy, but things get complicated with Student inheritance. Does anyone else think that the following three statements do essentially the same thing?

// define the Student class
function Student() {
  // Call the parent constructor
  Person.call(this);
}

// inherit Person
Student.prototype = new Person();

// correct the constructor pointer because it points to Person
Student.prototype.constructor = Student;

I understand the first one (calling the parent constructor) because is so similar to Java, PHP and so on. But then problems begin.

Why there is the need of calling Student.prototype and Student.prototype.constructor?

A clear explanation is needed. Why this code:

// define the Student class
function Student() {
  // Call the parent constructor
  Person.call(this);
}

var student1 = new Student();

is not enough for inheritance to work?

EDIT: regarding the constructor thing, it has been already answered here.

  • 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-10T14:32:56+00:00Added an answer on June 10, 2026 at 2:32 pm

    This doesn’t work:

    function Student() {
      Person.call(this);
    }
    
    var student1 = new Student();
    

    because Person‘s prototype properties are not available on Student instances. Person.call(this) merely calls Person with a specific this value (namely the Student instance). But the Person function is completely empty – so here it doesn’t do anything. There is no relation between Student and Person other than the useless Person call.

    To get Person‘s functions the .prototype assignment is necessary.

    Before:

    <a Student instance>
      its prototype: Student.prototype, with all student functions
        its prototype: Object.prototype
    

    After:

    <a Student instance>
      its prototype: <a Person instance>, with all student functions if you add them
        its prototype: Person.prototype, with all person functions
          its prototype: Object.prototype
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm reading Introduction to 3D Game Programming with DirectX 10 to learn some DirectX,
I am reading Apple's sample codes at: http://developer.apple.com/library/mac/#samplecode/CocoaSlides/Introduction/Intro.html it works on a NSView #import
Introduction We all know these silly arguments objects of JavaScript functions. But why object?
Greetings, After reading the following article I have a question: https://developer.mozilla.org/en/Introduction_to_Object-Oriented_JavaScript In the inheritance
Reading A re-introduction to JavaScript I noticed something interesting about functions: The name provided
After reading a memoization introduction I reimplemented the Fibonacci example by using a more
I was reading GADT introduction here and it I found the idea of restricting
I'm reading a book called Introduction to algorithms . I think many of you
Reading the docs, I'd expect $(#wrap2).remove(.error) to remove all .error elements from #wrap2 .
I'm reading Introduction to Algorithm by CLRS. In chapter 2, the authors mention loop

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.