You can use JSL classes to create objects, providing definitions for member variables, methods, and functions. The JSL function Define Class() has a number of arguments that define the contents of the class:
Define Class ( "class name" ),
Base Class ( "base class name", <"base class name">, ...),
Using Namespace ( namespace ), >
Show ( ( All (Boolean) | Members (Boolean) | Methods (Boolean) | Functions (Boolean) ) ),
< Assignment Statements >
);
•
|
"class name" is the name of the class being defined.
|
•
|
"base class name" are one or more class names that make the set of base classes that are used as the foundation of the class being created.
|
•
|
namespace defines a specific namespace that stores unscoped variables defined in methods and functions.
|
•
|
Show defines the value that appears when a class object is written out using the Show(), Print(), or Write() functions. Options include:
|
–
|
All (Boolean) shows all members, methods, and functions defined in a class object instance. The default value for All is true.
|
–
|
Members (Boolean) shows all member variables contained in a class object instance.
|
–
|
Methods (Boolean) shows all methods contained in a class object instance.
|
–
|
Functions (Boolean) shows all functions contained in a class object instance.
|
Note: You can specify either the All option or any number of the Members, Methods, and Functions options, but you cannot specify both options at the same time.
Note: Statements can be separated by either a comma or semicolon, but must be done consistently within the Define Class() function.
Define Class(
"Pet",
Show(All(false), Members(true), Methods(false), Functions(false)),
{
name = "",
species = "",
breed = "",
sex = "",
color = "",
coat = "",
_init_ = Method( { name, species, breed, sex, color, coat },
this:name = name;
this:species = species;
this:sex = sex;
this:color = color;
this:coat = coat;
),
_show_ = Method( {},
Return( To String() )
),
_to string_ = Method( {},
Return( To String() )
),
Get Name = Method( {},
Return( name )
),
Get Species = Method( {},
Return( species )
),
Get Breed = Method( {},
Return( breed )
),
Get Sex = Method( {},
Return( sex )
),
Get Color = Method( {},
Return( color )
),
To String = Method( {},
Return( name || " is a " || color || " colored " || breed ||
" with a " || coat || " coat " || species )
),
f = Function( {a, b},
Return ( a + b )
)
}
);
•
|
To override what contents should be shown, a class object is displayed using the Show(), Print(), or Write() function and defining a show Method() that returns a value to be used.
|
•
|
In cases when a string representation is needed, such as a Char() function or concatenation operator, define a To String method that will return a string result to be used.
|
New Object(
("Class Name" | Class Name ) ( constructor arguments )
);
New Object(
Class Reference ( constructor arguments )
);
New Object(
"Class Name" | Class Name
<, { constructor arguments } >
);
New Object(
Class Reference,
<, { constructor arguments } >
);
class = "Pet";
xa = New Object( Pet( "Oliver", "canine", "Schnauzer",
"M", "Black", "Rough" ) );
xb = New Object( class, {"Flynn", "canine", "CockoPoo",
"M", "Brown", "Curly"} );
xc = New Object( class( "Mandi", "canine", "King Charles Cavalier",
"F", "Ruby", "Smooth" ) );
xd = New Object( "Pet"("Charlie", "feline", "Asian",
"M", "White", "Smooth") );
xd1 = New Object( xd( "Fred", "feline", "Siamese",
"F", "Silver", "Smooth" ) );
xd2 = New Object( xd, {"Sam", "canine", "German Shepard",
"M", "Black and White", "Smooth"} );
Show( xa );
Show( xa );
Show( xb );
Show( xc );
Show( xd );
Show( xd1 );
Show( xd2 );
xdc = xd; // Makes a copy
xdc:name = "Jerry";
xdc:species = "canine";
xdc:breed = "Hound Dog";
xdc:color = "Purple";
Show( xd, xdc );