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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:35:00+00:00 2026-06-10T14:35:00+00:00

I am working my way through understanding how to create a constructor with properties

  • 0

I am working my way through understanding how to create a constructor with properties and methods. The one below I have written and tested but it does not work. Could someone take the time to help me understand what it is that would make this not work. Understand that I have searched Google, I am reading books, etc., but needs some hands on support in understanding the concept with creating my own. Thank you.

function ball( type, grip, shape ) {
  this.type = type;
  this.grip = grip;
  this.shape = shape;
  this.caught = function( who,how ) {
    this.who = who;
    this.how = how;
  };
  this.player = function() {
    return (who + "caught the ball" + how + "that was a" + type + "shaped like 
            a " + shape + "thrown with a" + grip);
    };
};

var baseball = new ball("Mickey Mantle","sliding","baseball","circle","fastball");

console.log(ball);

Edit:
From the answers below – thank you for sharing – I have created my jsfiddle and can’t comprehend why the caught property is not working. How am I supposed to set the attributes for this method??

http://jsfiddle.net/uYTW6/

  • 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-10T14:35:02+00:00Added an answer on June 10, 2026 at 2:35 pm

    In your player function, you need to reference the variables who, how, type, shape and grip using this, i.e.

    return (this.who + "caught the ball" + this.how + "that was a" + this.type + "shaped like 
            a " + this.shape + "thrown with a" + this.grip);
    };
    

    Furthermore, functions common to all objects of type ball should be put into the prototype, so that the function only will be created once:

    ball.prototype.player = function() {
        return (this.who + "caught the ball" + this.how + "that was a" + this.type + "shaped like a " + this.shape + "thrown with a" + this.grip);
        };
    }
    

    It is also common convention to start the constructor function name with an uppercase letter, like B in your case (so your constructor function’s name is Ball, not ball).

    Updated answer

    You forgot to call the caught function on the baseball object, like so:

    var baseball = new Ball("Mickey Mantle","sliding","baseball","circle","fastball");
    baseball.caught('me', 'by hand');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working my way through some ASP.NET MVC reading and I have a web
While working my way through the Android tutorials, I came across something I don't
I'm working my way through "Learning jQuery" (Third Edition). In Chapter 4: "Manipulating the
I'm working my way through displaying various data elements from parent & child data,
I'm working my way through Agile Web Development with Rails and am running into
I'm still working my way through some pretty basic Actionscript programming (in Flex), and
I've been working my way through Tim Heuer's Silverlight tuturial , in which you
I'm working my way through APress's Beginning Android 2 and I've made it all
Good Day, I a working my way through the official JavaFX FXML tutorial (See
Disclaimer, new to programming, working my way through C++ Prime Plus 6th ed. I'm

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.