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’

The result is like that, now I only have 2 questions:
redsheep.options.show().sizes, is to call out this variable, now I think it is too long. How do I make it likeredsheep.sizes?-
redsheep.options.show().eatis not inherit from thesheepclassgrass, and becameundefined. 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>
Adding a method to an object that returns its own properties is useless. Remove that and access the properties normally:
You can access it like this: