การเรนเดอร์th-TH

ตัวฉัน

Translation status: ภาษาไทย reader-locale proof. Term names and code fences follow the th-TH pack; supporting prose may still be English.

Refers to the current instance inside a method.

Aliases: self, this

Syntax: ตัวฉัน.<member>

Category#

object

Examples#

radix/corpus/ego/ego.fab (canonical · keyword)#

Refers to the current instance inside a method.

# =============================================================================
# ego — Refers to the current instance inside a method.
# =============================================================================
#
# What this teaches:
#   • Self-reference — `ego.<member>` accesses the current instance's fields and methods inside a ชนิด method.
#   • Method definition — functions defined inside a ชนิด block receive the instance as `ego`.
#
# Common mistakes:
#   • Using `ego` outside a ชนิด method — `ego` is only valid inside methods defined on a ชนิด (SEM008).
#
# See also: ของชนิด, ชนิด
# =============================================================================

# ego — current ชนิด instance reference
#
# ego.<field>
#
# GRAMMAR:
#   memberExpr inside ชนิด method :← 'ego' '.' ident
#
# EXPECTED OUTPUT:
#   capsa: prima

class Capsa {
    var string titulus

    fn narra() → string {
        # ego = the receiver instance
        return "capsa: " + self.titulus
    }
}

main {
    const Capsa capsa ← Capsa { titulus = "prima" }
    print capsa.narra()
}

Expected output:

capsa: prima