|
1 | | -*vim9class.txt* For Vim version 9.1. Last change: 2024 Mar 28 |
| 1 | +*vim9class.txt* For Vim version 9.1. Last change: 2024 Apr 13 |
2 | 2 |
|
3 | 3 |
|
4 | 4 | VIM REFERENCE MANUAL by Bram Moolenaar |
@@ -328,10 +328,27 @@ variables but they have no access to the object variables, they cannot use the |
328 | 328 | enddef |
329 | 329 | endclass |
330 | 330 |
|
331 | | -Inside the class the class method can be called by name directly, outside the |
332 | | -class the class name must be prefixed: `OtherThing.ClearTotalSize()`. To use |
333 | | -a class method from a parent class in a child class, the class name must be |
334 | | -prefixed. |
| 331 | +Inside the class, the class method can be called by name directly, outside the |
| 332 | +class, the class name must be prefixed: `OtherThing.ClearTotalSize()`. Also, |
| 333 | +the name prefix must be used for public class methods in the special contexts |
| 334 | +of class variable initializers and of lambda expressions and nested functions: |
| 335 | +> |
| 336 | + class OtherThing |
| 337 | + static var name: string = OtherThing.GiveName() |
| 338 | +
|
| 339 | + static def GiveName(): string |
| 340 | + def DoGiveName(): string |
| 341 | + return OtherThing.NameAny() |
| 342 | + enddef |
| 343 | +
|
| 344 | + return DoGiveName() |
| 345 | + enddef |
| 346 | +
|
| 347 | + static def NameAny(): string |
| 348 | + return "any" |
| 349 | + enddef |
| 350 | + endclass |
| 351 | +< |
335 | 352 |
|
336 | 353 | Just like object methods the access can be made protected by using an |
337 | 354 | underscore as the first character in the method name: > |
@@ -576,7 +593,7 @@ A class is defined between `:class` and `:endclass`. The whole class is |
576 | 593 | defined in one script file. It is not possible to add to a class later. |
577 | 594 |
|
578 | 595 | A class can only be defined in a |Vim9| script file. *E1316* |
579 | | -A class cannot be defined inside a function. |
| 596 | +A class cannot be defined inside a function. *E1429* |
580 | 597 |
|
581 | 598 | It is possible to define more than one class in a script file. Although it |
582 | 599 | usually is better to export only one main class. It can be useful to define |
@@ -972,8 +989,8 @@ The following example shows an enum with object variables and methods: > |
972 | 989 | echo Planet.Earth.has_rings |
973 | 990 | < |
974 | 991 | *E1421* *E1423* *E1424* *E1425* |
975 | | -Enums and their values are immutable. They cannot be modified after |
976 | | -declaration and cannot be utilized as numerical or string types. |
| 992 | +Enums and their values are immutable. They cannot be utilized as numerical or |
| 993 | +string types. Enum values can declare mutable instance variables. |
977 | 994 |
|
978 | 995 | *enum-name* |
979 | 996 | Each enum value object has a "name" instance variable which contains the name |
|
0 commit comments