2 * @fileoverview This file is to be used for testing the JSDoc parser
3 * It is not intended to be an example of good JavaScript OO-programming,
4 * nor is it intended to fulfill any specific purpose apart from
5 * demonstrating the functionality of the
6 * <a href='http://sourceforge.net/projects/jsdoc'>JSDoc</a> parser
8 * @author Gabriel Reid gab_reid@users.sourceforge.net
14 * Construct a new Shape object.
15 * @class This is the basic Shape class.
16 * It can be considered an abstract class, even though no such thing
17 * really existing in JavaScript
19 * @throws MemoryException if there is no more memory
20 * @throws GeneralShapeException rarely (if ever)
21 * @return {Shape|Coordinate} A new shape.
26 * This is an example of a function that is not given as a property
27 * of a prototype, but instead it is assigned within a constructor.
28 * For inner functions like this to be picked up by the parser, the
29 * function that acts as a constructor <b>must</b> be denoted with
30 * the <b>@constructor</b> tag in its comment.
33 this.getClassName
= function(){
38 * This is an inner method, just used here as an example
42 function addReference(){
49 * Create a new Hexagon instance.
51 * @class Hexagon is a class that is a <i>logical</i> sublcass of
52 * {@link Shape} (thanks to the <code>@extends</code> tag), but in
53 * reality it is completely unrelated to Shape.
54 * @param {int} sideLength The length of one side for the new Hexagon
56 * var h = new Hexagon(2);
59 * hex = new Hexagon(5);
60 * color = hex.getColor();
63 function Hexagon(sideLength
) {
68 * This is an unattached (static) function that adds two integers together.
69 * @param {int} One The first number to add
70 * @param {int} Two The second number to add
71 * @author Gabriel Reid
72 * @deprecated So you shouldn't use it anymore! Use {@link Shape#getClassName} instead.
74 function Add(One
, Two
){
80 * The color of this shape
83 Shape
.prototype.color
= null;
86 * The border of this shape.
90 Shape
.prototype.border
= function(){return border
;};
93 * These are all the instance method implementations for Shape
97 * Get the coordinates of this shape. It is assumed that we're always talking
98 * about shapes in a 2D location here.
99 * @requires The {@link Shape} class
100 * @returns A Coordinate object representing the location of this Shape
103 Shape
.prototype.getCoords
= function(){
108 * Get the color of this shape.
110 * @see The <a href="http://example.com">Color</a> library.
114 Shape
.prototype.getColor
= function(){
119 * Set the coordinates for this Shape
120 * @param {Coordinate} coordinates The coordinates to set for this Shape
122 Shape
.prototype.setCoords
= function(coordinates
){
123 this.coords
= coordinates
;
127 * Set the color for this Shape
128 * @param {Color} color The color to set for this Shape
129 * @param other There is no other param, but it can still be documented if
130 * optional parameters are used
131 * @throws NonExistantColorException (no, not really!)
134 Shape
.prototype.setColor
= function(color
){
140 * @returns A copy of this shape
142 * @author Gabriel Reid
144 Shape
.prototype.clone
= function(){
149 * Create a new Rectangle instance.
150 * @class A basic rectangle class, inherits from Shape.
151 * This class could be considered a concrete implementation class
153 * @param {int} width The optional width for this Rectangle
154 * @param {int} height Thie optional height for this Rectangle
155 * @author Gabriel Reid
156 * @see Shape is the base class for this
160 function Rectangle(width
, // This is the width
161 height
// This is the height
166 this.height
= height
;
172 /* Inherit from Shape */
173 Rectangle
.prototype = new Shape();
176 * Value to represent the width of the Rectangle.
177 * <br>Text in <b>bold</b> and <i>italic</i> and a
178 * link to <a href="http://sf.net">SourceForge</a>
182 Rectangle
.prototype.width
= 0;
185 * Value to represent the height of the Rectangle
189 Rectangle
.prototype.height
= 0;
192 * Get the type of this object.
195 Rectangle
.prototype.getClassName
= function(){
200 * Get the value of the width for the Rectangle
202 * @see Rectangle#setWidth
204 Rectangle
.prototype.getWidth
= function(){
209 * Get the value of the height for the Rectangle.
210 * Another getter is the {@link Shape#getColor} method in the
211 * {@link Shape} base class.
212 * @return The height of this Rectangle
214 * @see Rectangle#setHeight
216 Rectangle
.prototype.getHeight
= function(){
221 * Set the width value for this Rectangle.
222 * @param {int} width The width value to be set
225 Rectangle
.prototype.setWidth
= function(width
){
230 * Set the height value for this Rectangle.
231 * @param {int} height The height value to be set
234 Rectangle
.prototype.setHeight
= function(height
){
235 this.height
= height
;
239 * Get the value for the total area of this Rectangle
240 * @return total area of this Rectangle
243 Rectangle
.prototype.getArea
= function(){
244 return width
* height
;
249 * Create a new Square instance.
250 * @class A Square is a subclass of {@link Rectangle}
251 * @param {int} width The optional width for this Rectangle
252 * @param {int} height The optional height for this Rectangle
253 * @augments Rectangle
255 function Square(width
, height
){
259 this.height
= height
;
265 /* Square is a subclass of Rectangle */
266 Square
.prototype = new Rectangle();
269 * Set the width value for this Shape.
270 * @param {int} width The width value to be set
273 Square
.prototype.setWidth
= function(width
){
274 this.width
= this.height
= width
;
278 * Set the height value for this Shape
279 * Sets the {@link Rectangle#height} attribute in the Rectangle.
280 * @param {int} height The height value to be set
282 Square
.prototype.setHeight
= function(height
){
283 this.height
= this.width
= height
;
288 * Create a new Circle instance based on a radius.
289 * @class Circle class is another subclass of Shape
291 * @param {int} radius The optional radius of this {@link Circle }
292 * @mixin Square.prototype.setWidth as this.setDiameter
294 function Circle(radius
){
296 /** The radius of the this Circle. */
297 this.radius
= radius
;
301 /* Circle inherits from {@link Shape} */
302 Circle
.prototype = new Shape();
305 * The radius value for this Circle
309 Circle
.prototype.radius
= 0;
312 * A very simple class (static) field that is also a constant
319 * Get the radius value for this Circle
323 Circle
.prototype.getRadius
= function(){
328 * Set the radius value for this Circle
329 * @param {int} radius The {@link Circle#radius} value to set
332 Circle
.prototype.setRadius
= function(radius
){
333 this.radius
= radius
;
337 * An example of a class (static) method that acts as a factory for Circle
338 * objects. Given a radius value, this method creates a new Circle.
339 * @param {int} radius The radius value to use for the new Circle.
342 Circle
.createCircle
= function(radius
){
343 return new Circle(radius
);
348 * Create a new Coordinate instance based on x and y grid data.
349 * @class Coordinate is a class that can encapsulate location information.
350 * @param {int} [x=0] The optional x portion of the Coordinate
351 * @param {int} [y=0] The optinal y portion of the Coordinate
353 function Coordinate(x
, y
){
363 * The x portion of the Coordinate
368 Coordinate
.prototype.x
= 0;
371 * The y portion of the Coordinate
376 Coordinate
.prototype.y
= 0;
379 * Gets the x portion of the Coordinate.
383 Coordinate
.prototype.getX
= function(){
388 * Get the y portion of the Coordinate.
392 Coordinate
.prototype.getY
= function(){
397 * Sets the x portion of the Coordinate.
398 * @param {int} x The x value to set
401 Coordinate
.prototype.setX
= function(x
){
406 * Sets the y portion of the Coordinate.
407 * @param {int} y The y value to set
410 Coordinate
.prototype.setY
= function(y
){
415 * @class This class exists to demonstrate the assignment of a class prototype
416 * as an anonymous block.
418 function ShapeFactory(){
421 ShapeFactory
.prototype = {
423 * Creates a new {@link Shape} instance.
424 * @return A new {@link Shape}
427 createShape
: function(){
433 * An example of a singleton class
434 * @param ... Arguments represent {@link coordinate}s in the shape.
437 MySingletonShapeFactory
= function(){
440 * Get the next {@link Shape}
442 * @return A new {@link Shape}
444 this.getShape
= function(){
452 * Create a new Foo instance.
453 * @class This is the Foo class. It exists to demonstrate 'nested' classes.
460 * Creates a new instance of Bar.
461 * @class This class exists to demonstrate 'nested' classes.
471 Foo
.Bar
= function(){
472 /** The x. */ this.x
= 2;
475 Foo
.Bar
.prototype = new Bar();
477 Foo
.Bar
.prototype.y
= '3';