Skip to main content

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

.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

.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

ParameterTypeDescription
paramany->Parameter(s) to pass to the constructor function
Result4D.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.

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