Specifications

function y()
{
return m_y;
}
function r()
{
return m_r;
}
}
class ColorCircle extends Circle
{
var m_rgb;
function ColorCircle( posx, posy, radius, rgbcolor)
{
Circle( posx, posy, radius );
m_rgb = rgbcolor;
}
function setRgb( rgbcolor )
{
m_rgb = rgbcolor;
}
function rgb()
{
return m_rgb;
}
}
A class's constructor is the function which has the same (case-sensitive) name as the class itself.
The constructor should not contain an explicit return statement; it will return an object of its
type automatically. JavaScript does not have a destructor function (a function that is called when
the class is destroyed).
The class's member variables are declared with var, and its member functions with function.
The object instance itself is referred to using this operator. Inside a member function of a class,
member variables and member functions can be accessed with an explicit "this" (example: this.x
= posx;). This is not required, but can sometimes help to increase visibility.
JavaScript supports single inheritance and if a class inherits from another class, the superclass's
constructor can be called with super().
Qualified names
When an object of a particular type is declared, the object itself becomes, in effect, a namespace.
For example, in JavaScript there is a function called Math.sin(). If you wanted to have a sin()
function in your own class that would not be a problem, because objects of your class would call
the function using the object.function() syntax. The period is used to distinguish the namespace
a particular identifier belongs to.
In most cases JavaScript is intelligent enough to work out the fully qualified name on its own.
The only time that you need to qualify your names is when an unqualified name is ambiguous.
Class properties
A property is an undeclared variable that can be written to and accessed if the class supports
properties.
var obj = new Objectobject.myProperty = 100;
The class Object does not define the variable myProperty but since the class supports properties,
we can define the variable with that name on the fly and use it later. Properties are associated
370
Enfocus Switch 10