Saltar para o conteúdo principal
Versão: Próximo

Class

When a user class is defined in the project, it is loaded in the 4D language environment. Uma classe é um objeto em si mesmo, da classe "Class", que tem propriedades e uma função.

Resumo

.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

.isShared

História
ReleaseMudanças
20 R5Adicionado

.isShared : Boolean

Descrição

The .isShared property returns true if the user class has been defined as shared class, and false otherwise.

This property is read-only.

.isSingleton

História
ReleaseMudanças
20 R5Adicionado

.isSingleton : Boolean

Descrição

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

História
ReleaseMudanças
20 R5Adicionado

.me : 4D.Class

Descrição

The .me property returns the singleton instance of the cs.className singleton class. Se a classe singleton nunca tiver sido instanciada anteriormente, essa propriedade chamará o construtor da classe sem parâmetros e criará a instância. Caso contrário, ele retorna a instância singleton existente.

If cs.className is not a singleton class, .me is undefined by default.

This property is read-only.

.name

História
ReleaseMudanças
18 R3Adicionado

.name : Text

Descrição

The .name property contains the name of the 4D.Class object. Nomes de classe diferenciam minúsculas de maiúsculas.

This property is read-only.

.new()

História
ReleaseMudanças
18 R3Adicionado

.new( { ...param : any } ) : 4D.Class

ParâmetroTipoDescrição
paramany->Parâmetros a passar à função constructor
Resultados4D. Class<-Novo objeto da classe

Descrição

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.

Notas
  • 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.

Exemplos

Para criar uma nova instância da classe Person com parâmetros:

var $person : cs. Person  
$person:=cs. Person.new() //create the new instance
//$person contains functions of the class

Para criar uma nova instância da classe Person:

//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

História
ReleaseMudanças
18 R3Adicionado

.superclass : 4D.Class

Descrição

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.

Exemplos

$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