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
.name : Text contains the name of the |
.new( param : any { ;...paramN } ) : 4D.Class creates and returns a |
.superclass : 4D.Class returns the parent class of the class |
.name
History
Version | Changes |
---|---|
v18 R3 | Added |
.name : Text
Beschreibung
The .name
property contains the name of the 4D.Class
object. Es wird zwischen Groß- und Kleinschreibung unterschieden.
This property is read-only.
.new()
History
Version | Changes |
---|---|
v18 R3 | Added |
.new( param : any { ;...paramN } ) : 4D.Class
Parameter | Typ | Beschreibung | |
---|---|---|---|
param | any | -> | Parameter(s) to pass to the constructor function |
Ergebnis | 4D.Class | <- | New object of the class |
Beschreibung
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.
Beispiele
Eine neue Instanz der Klasse Person anlegen:
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
Version | Changes |
---|---|
v18 R3 | Added |
.superclass : 4D.Class
Beschreibung
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.
Beispiele
$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