Skip to content

Commit 7b59ea1

Browse files
authored
Merge pull request #1490 from vim-jp/hh-update-vim9class
Update vim9class.{txt,jax}
2 parents b728ff0 + defc29e commit 7b59ea1

File tree

2 files changed

+52
-17
lines changed

2 files changed

+52
-17
lines changed

doc/vim9class.jax

+27-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*vim9class.txt* For Vim バージョン 9.1. Last change: 2024 Mar 28
1+
*vim9class.txt* For Vim バージョン 9.1. Last change: 2024 Apr 13
22

33

44
VIMリファレンスマニュアル by Bram Moolenaar
@@ -323,10 +323,28 @@ new() メソッドを定義するときは、戻り値の型を指定しない
323323
enddef
324324
endclass
325325
326-
クラス内ではクラスメソッドを名前で直接呼び出すことができるが、クラスの外ではク
327-
ラス名はプリフィックス付きである必要がある: `OtherThing.ClearTotalSize()`。親
328-
クラスのクラスメソッドを子クラスで使用するには、クラス名をプリフィックスとして
329-
付ける必要がある。
326+
クラス内では、クラスメソッドを名前で直接呼び出すことができるが、クラスの外で
327+
は、クラス名がプリフィックスされている必要がある:
328+
`OtherThing.ClearTotalSize()`。また、クラス変数初期化子、ラムダ式、入れ子になっ
329+
た関数といった特殊なコンテキストでは、パブリッククラスメソッドに名前プリフィッ
330+
クスを使用しなければならない:
331+
>
332+
class OtherThing
333+
static var name: string = OtherThing.GiveName()
334+
335+
static def GiveName(): string
336+
def DoGiveName(): string
337+
return OtherThing.NameAny()
338+
enddef
339+
340+
return DoGiveName()
341+
enddef
342+
343+
static def NameAny(): string
344+
return "any"
345+
enddef
346+
endclass
347+
<
330348

331349
オブジェクトメソッドと同様に、メソッド名の最初の文字としてアンダースコアを使用
332350
することで、アクセスを protected にすることができる: >
@@ -571,8 +589,8 @@ Shape, Square および Triangle を使用した上記の例は、オブジェ
571589
クラスは `:class``:endclass` の間で定義される。クラス全体は 1 つのスクリプ
572590
トファイルで定義される。後からクラスに追加することはできない。
573591

574-
クラスは |Vim9| script ファイル内でのみ定義できる。 *E1316*
575-
関数内でクラスを定義することはできない。
592+
クラスは |Vim9| script ファイル内でのみ定義できる。 *E1316*
593+
関数内でクラスを定義することはできない。 *E1429*
576594

577595
スクリプトファイル内に複数のクラスを定義することは可能である。しかし、通常はメ
578596
インクラスを 1 つだけエクスポートする方が良い。型、列挙型、ヘルパークラスを定
@@ -959,8 +977,8 @@ Note メソッド名は "new" で始まる必要があることに注意。"new(
959977
echo Planet.Earth.has_rings
960978
<
961979
*E1421* *E1423* *E1424* *E1425*
962-
列挙型とその値は不変である。宣言後に変更したり、数値型または文字列型として使用
963-
したりすることはできない
980+
列挙型とその値は不変である。数値型または文字列型として使用することはできない。
981+
列挙値は変更可能なインスタンス変数を宣言できる
964982

965983
*enum-name*
966984
各列挙値オブジェクトには、列挙値の名前を含む "name" インスタンス変数がある。こ

en/vim9class.txt

+25-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -328,10 +328,27 @@ variables but they have no access to the object variables, they cannot use the
328328
enddef
329329
endclass
330330
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+
<
335352

336353
Just like object methods the access can be made protected by using an
337354
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
576593
defined in one script file. It is not possible to add to a class later.
577594

578595
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*
580597

581598
It is possible to define more than one class in a script file. Although it
582599
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: >
972989
echo Planet.Earth.has_rings
973990
<
974991
*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.
977994

978995
*enum-name*
979996
Each enum value object has a "name" instance variable which contains the name

0 commit comments

Comments
 (0)