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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:28:29+00:00 2026-06-15T11:28:29+00:00

I have tested quite a bit about making classes, now I finally discovered how

  • 0

I have tested quite a bit about making classes, now I finally discovered how it works, that’s what I want to make class simple and clear, without spamming ‘this’

enter image description here

The result is like that, now I only have 2 questions:

  1. redsheep.options.show().sizes, is to call out this variable, now I think it is too long. How do I make it like redsheep.sizes?
  2. redsheep.options.show().eat is not inherit from the sheepclass grass, and became undefined. How do I make default values for newly created objects?

    <html>
    <head>
    <meta charset='utf-8'>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <title>A simple javascript function</title>
    <script type="text/javascript">
        $(document).ready(function(){
            var sheepclass = function(options){
                this.options = {'sizes' : 'thin',
                        'eat'   : 'grass',
                        'color' : 'white',
                        show    : function(){
                                    return {'color':options.color,
                                             'eat':options.eat,
                                             'sizes':options.sizes
                                            };
                                 }
                 }
            }
    
            var blacksheep = new sheepclass({'color':'black'});
            var redsheep   = new sheepclass({'color':'red','sizes':'fat'});
    
            $('div').append('<p>blackcsheep color : ' +
                            blacksheep.options.show().color);
            $('div').append('<p>redsheep color : ' + 
                            redsheep.options.show().color +
                            '<p>redsheep size:' +
                            redsheep.options.show().sizes +
                            '<p> redsheep eat:' + 
                            redsheep.options.show().eat);
        })
    </script>
    <style>
        div{display:block;width:800px;height:400px;border:2px solid red;}
    </style>
    </head>
    <body>
        <div>
              Result:
        </div>
    </body>
    </html>
    
  • 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-15T11:28:30+00:00Added an answer on June 15, 2026 at 11:28 am

    Adding a method to an object that returns its own properties is useless. Remove that and access the properties normally:

    var sheepclass = function(options) {
        this.options = $.extend({
            'sizes': 'thin',
            'eat': 'grass',
            'color': 'white',
        }, options);
    }
    

    You can access it like this:

    redsheep.options.eat
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following bit of code, used on Android and tested quite extensively
I have tested Play now for quite a while and everything is set up
I have tested this servlet and it works well, except in Google Chrome it
i have tested standardanalyzer with indexWriter and found that it automatically removes stopwords, however,
How to make CITE tag entirely indented? I have tested all of the padding-left:
I have tested this and the reason I asked the question is that it
I have been digging quite a bit on Sonar best practices. The consensus seems
Well, my problem is quite strange, because it really doesn't make sense. 1)I have
i have a quite strange problem. my class has -among others- following memers: GLboolean
I have searched quiet a bit and found a lot of css that I

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.