ของชนิด
Translation status: ภาษาไทย reader-locale proof. Term names and code fences follow the th-TH pack; supporting prose may still be English.
Marks a class member as belonging to the type itself.
Syntax: ของชนิด <type> <name> [= <expression>]
Category#
type
Related#
Examples#
radix/corpus/generis/generis.fab (canonical · keyword)#
Marks a class member as belonging to the type itself.
# =============================================================================
# ของชนิด — Marks a class member as belonging to the type itself
# =============================================================================
#
# What this teaches:
# • Marks a class member as belonging to the type itself.
# • Related keywords: ชนิด, ego
#
# Common mistakes:
# • Accessing a `ของชนิด` field on an instance instead of the type — `ของชนิด` fields are static members accessed via the ชนิด name, not via `ego`.
#
# See also: ชนิด, ego
# =============================================================================
# ของชนิด marks a static ชนิด field (shared across instances)
#
# ของชนิด <type> <field> = <initium> -- class-level binding, not per-instance
#
# GRAMMAR:
# fieldDecl inside genusDecl :← 'ของชนิด'? type ident ('=' expr)?
#
# EXPECTED OUTPUT:
# ruber
#
# Instance field `ชื่อ` is per-object; `ของชนิด ruber` would be accessed on the
# ชนิด type in full programs (here only instance fields are read).
class Color {
static string ruber = "#ff0000"
var string ชื่อ = "ruber"
}
main {
const Color color ← Color {}
print color.nomen
}Expected output:
ruber