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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:54:40+00:00 2026-06-15T13:54:40+00:00

I am new in JS programming and trying to understand prototype-based inheritance. below is

  • 0

I am new in JS programming and trying to understand prototype-based inheritance. below is my test code and I have a question about line method ‘parseParameters’.

As I know, when I am instantiating class Point and wring following:

var p = new Point ({x: 1, y: 1});
alert(p.x);

member ‘x’ firstly searched in the Point class, then in its prototype (Shape). Is it right?

And question itself: where will be created members ‘x’ and ‘y’ – in the Point class or in Shape (prototype)?

One remark: should I actually thinking of it? Maybe it is negligible question and there is no matter where the member created?

var Shape = function () {}

Shape.prototype = {
    getParameter: function (params, name) {
        return params !== null && params !== undefined
            ? params[name]
            : 0;
    },

    parseParameters: function(params, names) {
        if (params === null || params === undefined) {
            return;
        }

        for(var i = 0; i < names.length; i++) {
            this[names[i]] = params[names[i]];
        }
    }
}

var Point = function (params) {
    this.parseParameters(params, ['x', 'y'])
}

Point.prototype = new Shape;
  • 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-15T13:54:41+00:00Added an answer on June 15, 2026 at 1:54 pm

    p.x

    member ‘x’ firstly searched in the Point class, then in its prototype (Shape). Is it right?

    Apart from that there are no “classes” in JavaScript, yes. The property name will first be searched on the p object itself, then in the object it did inherit from (there’s an internal link).

    Where will be created members ‘x’ and ‘y’ – in the Point class or in Shape (prototype)?

    Depends on how you create them 🙂

    In a simple assignment, like p.x = 1; (which also happens in parseParameters‘ this[names[i]] = params[names[i]], as this === p) the property will be created on the p object.

    should I actually thinking of it? Maybe there is no matter where the member created?

    No, that really matters. If you would create them on the prototype object, all objects which inherit from that one would share the same values. While this is useful for the functions, it would be catastrophic for data properties like x and y which should differ from instance to instance (see also Why are my JavaScript object properties being overwritten by other instances? for an example).

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

Sidebar

Related Questions

I rather like the prototype way of programming and have been trying to understand
I'm trying to understand the add method in below class taken from book 'Programming
I am new in C programming, and trying to create simple code below for
I'm new to programming with linux and I was trying to understand how fork()
I'm still new to programming/Java/Android so I'm trying to understand everything I do and
I'm fairly new to C programming but trying my best to understand it. I
i am enthusiast and new in programming trying this simple c language code and
i am new in programming under linux and trying to get working this code:
i am new kernel programming.i have been trying to load this driver program for
I'm new to OO programming, and I'm trying to understand how to assign values

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.