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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:02:49+00:00 2026-05-26T11:02:49+00:00

If I have a dummy constructor object: function Circle() { this.radius = 3; }

  • 0

If I have a dummy constructor object:

function Circle()
{
    this.radius = 3;
}

An instance of this object would have the single “radius” property. a) How do I query the constructor object for the number of properties it has?

b) How would I query Circle.prototype for the number of properties it has? Trying something like console.log(Object.getOwnPropertyNames(Circle.prototype)) doesn’t return anything

  • 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-26T11:02:49+00:00Added an answer on May 26, 2026 at 11:02 am

    You have several terminology things wrong.

    1. You don’t “query the constructor object”. You can enumerate the properties of an actual object, but not the constructor function.
    2. The way you are creating properties in your code example, you are not using the object’s prototype so if you were to iterate the object’s prototype, you would not see the radius property.

    Assuming what you really meant to say is: “How do I iterate over the properties of an instance of my Circle object?”, the answer would be like this:

    function Circle()
    {
        this.radius = 3;
        this.border = 1;
        this.color = "red";
    }
    
    var obj = new Circle();
    for (var i in obj) {
        // hasOwnProperty makes sure we get properties only of Circle, 
        // not of ancestors like Object
        if (obj.hasOwnProperty(i)) {
            // i will be properties of obj on each iteration
            console.log(i);      // radius, border, color
        }
    }
    

    The prototype of an object is a different thing. You can think of it like a structure that every new instance of your object inherits automatically. You could use the prototype like this:

    function Circle(r)
    {
        this.radius = r;
        this.border = 1;
        this.color = "red";
    }
    
    Circle.prototype.calcArea = function() {
        return(Math.PI * this.radius * this.radius);
    }
    
    Circle.prototype.calcCircumference = function() {
        return(Math.PI * this.radius * 2);
    }
    

    This will automatically give every instance of Circle, two methods calcArea and calcCircumference.

    var cir = new Circle(4);
    console.log(cir.calcArea());    // 54.624
    

    You can also add methods to the prototype of pre-existing objects that you do not have the code for such as Array (though you have to be careful when doing this). For example:

    Array.prototype.isSorted = function() {
        for (var i = 1; i < this.length; i++) {
            if (this[i] < this[i-1]) {
                return(false);
            }
        }
        return(true);
    }
    
    var x = [1,3,6,8];
    var y = [1,3,8,6];
    
    console.log(x.isSorted());    // true
    console.log(y.isSorted());    // false
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a generic method with this (dummy) code (yes I'm aware IList has
I have an object of class which has private constructor: class CL_GUIComponent { //
I have to create an object X using properties of object Y (both are
I have a dummy question. I would like to print an integer into a
I have this dummy target: <mkdir dir=${project.stage}/release <war destfile=${project.stage}/release/sigma.war> ... ... </war> What I
I have a dummy class where I am testing arrays. I've noticed that when
Let's say I have the following content: Lorem Ipsum is simply dummy text of
Image Dummy = Image.FromFile(image.png); Dummy.Save(image.bmp, ImageFormat.Bmp); what the question says i have these using
I have a table with three fields, FirstName, LastName and Email. Here's some dummy
So, I have a file called 'dummy' which contains the string: There is 100%

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.