Class
When a user class is defined in the project, it is loaded in the 4D language environment. A class is an object itself, of "Class" class, which has properties and a function.
Summary
.isSessionSingleton
History
| Release | Changes | 
|---|---|
| 20 R7 | Added | 
.isSessionSingleton* : Boolean
Description
The .isSessionSingleton property returns true if the user class has been defined as a session singleton class, and false otherwise.
This property is read-only.
.isShared
History
| Release | Changes | 
|---|---|
| 20 R5 | Added | 
.isShared* : Boolean
Description
The .isShared property returns true if the user class has been defined as shared class, and false otherwise.
This property is read-only.
.isSingleton
History
| Release | Changes | 
|---|---|
| 20 R5 | Added | 
.isSingleton* : Boolean
Description
The .isSingleton property returns true if the user class has been defined as a singleton class, and false otherwise.
This property is read-only.
.me
History
| Release | Changes | 
|---|---|
| 20 R5 | Added | 
.me* : 4D.Object
Description
The .me property returns the singleton instance of the cs.className singleton class. If the singleton class was never instantiated beforehand, this property calls the class constructor without parameters and creates the instance. Otherwise, it returns the existing singleton instance.
If cs.className is not a singleton class, .me is undefined by default.
This property is read-only.
.name
History
| Release | Changes | 
|---|---|
| 18 R3 | Added | 
.name* : Text
Description
The .name property contains the name of the 4D.Class object. Class names are case sensitive.
This property is read-only.
.new()
History
| Release | Changes | 
|---|---|
| 18 R3 | Added | 
.new*( { ...param : any } ) : 4D.Object
| Parameter | Type | Description | |
|---|---|---|---|
| param | any | -> | Parameter(s) to pass to the constructor function | 
| Result | 4D.Object | <- | New object of the class | 
Description
The .new() function creates and returns a cs.className object which is a new instance of the class on which it is called. This function is automatically available on all classes from the cs class store.
You can pass one or more optional param parameters, which will be passed to the class constructor function (if any) in the className class definition. Within the constructor function, the This is bound to the new object being constructed.
- If .new()is called on a singleton class that has already been instantiated, the singleton instance is returned, not a new instance.
- If .new()is called on a non-existing class, an error is returned.
Examples
To create a new instance of the Person class:
var $person : cs.Person  
$person:=cs.Person.new() //create the new instance  
//$person contains functions of the class
To create a new instance of the Person class with parameters:
//Class: Person.4dm
Class constructor($firstname : Text; $lastname : Text; $age : Integer)
	This.firstName:=$firstname
	This.lastName:=$lastname
	This.age:=$age
//In a method
var $person : cs.Person  
$person:=cs.Person.new("John";"Doe";40)  
//$person.firstName = "John"
//$person.lastName = "Doe"
//$person.age = 40
.superclass
History
| Release | Changes | 
|---|---|
| 18 R3 | Added | 
.superclass* : 4D.Class
Description
The .superclass property returns the parent class of the class. A superclass can be a 4D.Class object, or a cs.className object. If the class does not have a parent class, the property returns null.
To define a superclass for a user class, use the  extends keyword like: Class extends <superclass>.
This property is read-only.
Examples
$sup:=4D.File.superclass //Document
$sup:=4D.Document.superclass //Object
$sup:=4D.Object.superclass //null
// If you created a MyFile class  
// with `Class extends File`
$sup:=cs.MyFile.superclass //File
See also: Super