Entity Methods
- Add of Entity after a function name to attach behavior to that receiver.
- self is the current receiver and has the exact entity or child-entity type.
- Built-in collection and primitive methods remain owned by their receiver types.
Attaching A Method
1bool fn isLarge of Expense {2 return self.amount >= 1003}45string fn displayTitle of Expense {6 return self.title.trim()7}of Expense attaches the function to Expense. Inside the body, self is the current expense. Outside the declaration, call the method through an expense value.
Calling A Method
1if expense.isLarge() {2 review_required = true3}45label = expense.displayTitle()The receiver before the dot chooses the method namespace. Nenu checks that the method exists for the resolved receiver type and that its parameters and return value match the call site.
Mutating Through Self
1fn recordSettlementTime(time settled_at) of Settlement {2 self.settled_at = settled_at3}Child Entity Methods
1bool fn hasPositiveShare of Expense.shares {2 return self.amount > 03}Use the exact dotted child type after of. The parent segment is PascalCase and the child segment is lower-camel, matching the child entity declaration. Define that relationship first on the Relationships And Children page.
Receiver-Specific Built-Ins
- Arrays own methods such as
filter,collect, andpush. - Strings own methods such as
trimandcontains. - Numbers and time values own their documented primitive methods.
- An entity does not inherit the methods of one of its fields.
- A custom entity method may reuse a name owned by an unrelated receiver, but cannot replace a built-in on the same resolved receiver type.
1fn filter of Expense {2 return self3}Common Mistakes
| Wrong | Correct |
|---|---|
fn isLarge(Expense self) | fn isLarge of Expense |
Use this | Use self. |
| Assume mutation saves automatically | Call save at the owning backend workflow boundary. |
Attach to Expense.Shares | Use Expense.shares. |
