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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:35:28+00:00 2026-06-07T08:35:28+00:00

I was trying to learn OO techniques in javascript. Most of the web sites

  • 0

I was trying to learn OO techniques in javascript. Most of the web sites use prototype inheritance.

But, I am trying to understand why the following is bad (and still can achieve what prototype inheritance can do):

        //create parent class
    var Person = function (vId, vName) {
        this.Id = vId;
        this.Name = vName;

        this.Display = function () {
            alert("Id=" + this.Id);
        }
    };

    //create new class
    var Emp = function (vId, vName, vOfficeMail) {
        Person.call(this, vId, vName)
        this.OfficeEmail = vOfficeMail;

        this.Display = function () {
            alert("Id=" + this.Id + ", OfficeMail=" + this.OfficeEmail);
        }
    };

    //create instance of child class
    var oEmp = new Emp(1001, "Scott", "a@a.com"); //using Child's constructor
    //call display method in child class
    oEmp.Display();

    //create instance of parent class
    var oPerson = new Person(1002, "Smith"); //using Parent's constructor
    //call display method in parent class
    oPerson.Display();
  • 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-07T08:35:30+00:00Added an answer on June 7, 2026 at 8:35 am

    This is what I think is the most important, and a simple explanation.

    This code will create the function once for each object:

    this.Display = function () {
        alert("Id=" + this.Id);
    }
    

    Using prototypes, the function is instead created only once and applied to all objects of that kind. Wastes less memory and less CPU-power.

    This code will show what I’m talking about:

    var Person = function (vId, vName) {
            this.Id = vId;
            this.Name = vName;
    
            this.Display = function () {
                alert("Id=" + this.Id);
            }
        };
    
        var a = new Person(1, 2);
        var b = new Person(3, 4);
    
        var instanceEqual = (a.Display == b.Display);// false
        alert("Instance functions equal: " + instanceEqual);
    
        Person.prototype.Display2 = function () {
                alert("Id=" + this.Id);
            }
    
        var prototypeEqual = (a.Display2 == b.Display2);// true
        alert("Prototype functions equal: " + prototypeEqual);
    

    Jsfiddle: http://jsfiddle.net/nPnrk/

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

Sidebar

Related Questions

I am trying learn the use of lambda expressions and hence still struggling to
im trying to learn delegates and events in c#, i understand that an event
I am currently trying to learn some more about web design and I used
I was trying learn lex and yacc using the oreilly book. I tried following
I'm new to coding. I'm trying new things to learn better coding techniques. Right
I'm trying to dissect some well designed sites, in order to learn more about
Trying to learn jquery here so I took a regular javascript snippet that loops
I am very much new to android and trying to learn various techniques including
I'm trying to learn SQLite and searching for techniques to speed up my query.
I am still trying to learn Java and decided to take it 1 step

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.