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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:10:16+00:00 2026-06-15T11:10:16+00:00

I am viewing Tuts+ OO JavaScript training: The way they do prototypical inheritance looks

  • 0

I am viewing Tuts+ OO JavaScript training: The way they do prototypical inheritance looks like:

Employee.prototype = Object.create(Person.prototype);

But why cant I do just (without object create)

Employee.prototype = Person.prototype;

The 2nd will give an infinite loop: http://jsfiddle.net/VMqSy/

Why? Console logging the prototypes tells me that the 1 with Object.create() will give Employee.prototype 1 more level of __proto__ which is the Person.prototype, I think

  • 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-15T11:10:18+00:00Added an answer on June 15, 2026 at 11:10 am

    If you do (as shown in the fiddle)

    Employee.prototype = Person.prototype;
    

    then Employee will not be a subclass of Person, but rather they will become the same class (albeit with two different constructors).

    More exactly, the methods and properties that you add to the prototype of Employee will be also visible for any Person. Note that classes in OOP should not affect their superclass in any way.


    Employee.prototype = Object.create(Person.prototype);
    

    will create a new Object, similarly to

    Employee.prototype = {};
    Employee.prototype.__proto__ = Person.prototype
    

    except Object.create (unlike __proto__) works in all browsers, or to

    Employee.prototype = new Person();
    

    except the constructor of Person may also set additional properties to Employee.prototype while Object.create will create an object without extra properties.


    The infinite loop in your fiddle happens because Employee.prototype.sayHi calls Person.prototype.sayHi, but Employee.prototype.sayHi is Person.prototype.sayHi, and thus it calls itself (the original Person.prototype.sayHi was lost when you assigned to Employee.prototype.sayHi).

    If Employee.prototype === Person.prototype then, neccessarily, Employee.prototype.sayHi === Person.prototype.sayHi.

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

Sidebar

Related Questions

From viewing the source code that this code makes it looks like itemValue generate
When viewing lots of webpages' source code (like JS,CSS,HTML), I find them in one
When viewing submitted changelists in p4v, is there a way to display a particular
When viewing piped output to Less, sometimes I'd like to be able to view
Viewing WCF in its use as a way to do RPC between remote PCs
I’m viewing a log of file names and the times they were last modified
Viewing source, I have table data formatted exactly like this: <tr class=even> <td>apple</td> <td>pear</td>
I'm interested in viewing the topology of my branches, ideally in a pretty way
My UITableViewCells take up the full viewing area. I'd like to use a grouped
I'm using a JViewport for viewing some data and I'd like the header row

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.