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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:13:02+00:00 2026-05-15T23:13:02+00:00

<html> <head> <script> function SuperClass() { var self = this; self.someVariable = true; }

  • 0
<html>
<head>
<script>

function SuperClass()
{
    var self = this;
    self.someVariable = true;
}
function SubClass()
{
    var self = this;
    self.name = "Sub";
}
SubClass.prototype = SuperClass;

var sub = new SubClass();

alert("This is a sub class with name " + sub.name + " and variable " + sub.someVariable);

</script>
</head>
<body>
</body>
</html>

output:

This is a sub class with name Sub and variable undefined

So how come sub class doesnt have someVariable? I thought thats the whole point of prototyping.

  • 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-15T23:13:03+00:00Added an answer on May 15, 2026 at 11:13 pm

    You are simply assigning a reference to the SuperClass constructor to the SubClass.prototype, you need to use the new operator to make this SubClass.prototype object an instance of SuperClass:

    //...
    SubClass.prototype = new SuperClass();
    //..
    

    You may want to restore the constructor property of the SubClass.prototype object after the above line, because if you don’t do it, the instances created with SubClass (like sub in your example) will have an inherited constructor property wrongly pointing to SuperClass:

    SubClass.prototype.constructor = SubClass;
    

    Check an example here.

    Recommended articles:

    • Constructors considered mildly confusing
    • Object Oriented Programming in JavaScript
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 515k
  • Answers 516k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The problem is that the transformation you are using does… May 16, 2026 at 6:41 pm
  • Editorial Team
    Editorial Team added an answer select t.patient_id, max(t.visit_id) from (select t.patient_id, max(t.visit_date) maxdate from table… May 16, 2026 at 6:40 pm
  • Editorial Team
    Editorial Team added an answer Use AsyncTask instead. It has a function called onPostExecute where… May 16, 2026 at 6:40 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Why the following code doesn't work? <html> <head> <script type=text/javascript> function addTable() { var
I have this piece of simple code. <html> <head> <script type=text/javascript> function changeText() {
Assuming this: <html> <head> <script type=text/javascript src=jquery.js></script> <script type=text/javascript> $(document).ready(function(){ $(svg).append('<circle cx=100 cy=50 r=40
So, I wrote a small page: <html> <head> <script type=text/javascript src=jquery.js></script> <script> function slide()
For example: script.js: function functionFromScriptJS() { alert('inside functionFromScriptJS'); } iframe.html: <html> <head> <script language=Javascript
I have the following html in page: <head> <script src=jquery-1.3.2.min.js type=text/javascript></script> <script> function hideIt()
<html> <head> <script type='text/javascript' language='javascript' src=http://localhost/javascript/jquery-1.4.2.js> </script> <script type='text/javascript' language='javascript'> $(document).ready(function(){ $(#button).mousedown(function(){ dropDownMenu =
my code: <html> <head> <script type=text/JavaScript src=jquery-1.3.2.min.js></script> <script type=text/JavaScript src=jquery.center.js></script> <script type=text/JavaScript> $(document).ready(function(){ $('a').click(function(){
This is the piece of code I have written: <html> <head> <script type=text/javascript src=jquery-min.js></script>
This is an html page : <html> <head> <title> Frame Set </title> <script type=text/javascript

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.