Class
When a user class is defined in the project, it is loaded in the QodlyScript environment. A class is an object itself, of "Class" class, which has properties and a function.
Functions and properties
.isSessionSingleton : boolean returns true if the user class has been defined as a session singleton class |
.isShared : boolean returns true if the user class has been defined as shared class |
.isSingleton : boolean returns true if the user class has been defined as a singleton class |
.me : 4D.Class returns the singleton instance of the cs.className singleton class |
.name : Text contains the name of the 4D.Class object |
.new( { ...param : any } ) : 4D.Class creates and returns a cs.className object which is a new instance of the class on which it is called |
| .superclass : 4D.Class returns the parent class of the class |
.isSessionSingleton
.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
.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
.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
.me : 4D.Class
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
.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()
.new( { ...param : any } ) : 4D.Class
| Parameter | Type | Description | |
|---|---|---|---|
| param | any | → | Parameter(s) to pass to the constructor function |
| Result | 4D.Class | ← | 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 non-existing class, an error is returned. - If
.new()is called on a singleton class that has already been instantiated, the singleton instance is returned, not a new instance.
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
constructor(firstname : string, lastname : string, 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
.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.
A superclass of a user class is declared in a class by using the Class extends <superclass> keyword.
This property is read-only.
Examples
var sup: variant
sup = 4D.File.superclass //Document
sup = 4D.Document.superclass //Object
sup = 4D.Object.superclass //null
// If you created a MyFile class
// with `extends File`
sup = cs.MyFile.superclass //File
See also: Super