Skip to content

Commit dcda94c

Browse files
committed
Update vim9class.{txt,jax}
1 parent e1c9131 commit dcda94c

File tree

2 files changed

+28
-44
lines changed

2 files changed

+28
-44
lines changed

doc/vim9class.jax

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*vim9class.txt* For Vim バージョン 9.1. Last change: 2024 Dec 29
1+
*vim9class.txt* For Vim バージョン 9.1. Last change: 2025 Feb 16
22

33

44
VIMリファレンスマニュアル by Bram Moolenaar
@@ -53,7 +53,6 @@ script や従来の関数では使用できない。
5353
クラス階層は単一の継承になる。それ以外の場合は、必要に応じてインターフェイスを
5454
使用すること。
5555

56-
5756
クラスのモデリング ~
5857

5958
好きな方法でクラスをモデル化できる。何を構築しているのかを念頭に置き、現実世界
@@ -123,7 +122,6 @@ new() メソッドを使用して、このクラスからオブジェクトを
123122
クラス名を式として使用することはできない。クラス名は、代入の左辺では使用できな
124123
い。
125124

126-
127125
オブジェクト変数の書き込みアクセス ~
128126
*read-only-variable*
129127
では、オブジェクト変数を直接変更してみよう: >
@@ -267,6 +265,9 @@ new() を使用して変数をパブリックにするこの方法をまとめ
267265
new() メソッドを定義するときは、戻り値の型を指定しないこと。常にクラスのオブ
268266
ジェクトを返す。
269267

268+
new() メソッドは、"_new()" を使用して protected メソッドにすることができる。こ
269+
れは、シングルトン設計パターンをサポートするために使用できる。
270+
270271
*E1386*
271272
オブジェクトメソッドを呼び出すときは、メソッド名の前にオブジェクト変数名を付け
272273
る必要がある。クラス名を使用してオブジェクトメソッドを呼び出すことはできない。
@@ -620,13 +621,15 @@ Shape, Square および Triangle を使用した上記の例は、オブジェ
620621
extends ClassName
621622
implements InterfaceName, OtherInterface
622623
specifies SomeInterface
623-
< *E1355* *E1369*
624+
<
625+
"specifies" 機能は現在実装されていない。
626+
627+
*E1355* *E1369*
624628
各変数とメソッドの名前は 1 回だけ使用できる。同じ名前で異なる型の引数を持つメ
625629
ソッドを定義することはできない。パブリックと protected のメンバー変数を同じ名
626630
前で使用することはできない。スーパークラスで使用したオブジェクト変数名を子クラ
627631
スで再利用することはできない。
628632

629-
630633
オブジェクト変数の初期化 ~
631634

632635
変数の型がクラスで明示的に指定されていない場合、クラス定義時に "any" に設定さ
@@ -681,13 +684,12 @@ Shape, Square および Triangle を使用した上記の例は、オブジェ
681684
のみ使用できる *E1350* 。複数のインターフェイスをコンマで区切って指定できる。
682685
各インターフェイス名は 1 回だけ出現できる。 *E1351*
683686

684-
685687
インターフェイスを定義するクラス ~
686688
*specifies*
687689
クラスは、名前付きインターフェイスを使用して、そのインターフェイス、オブジェク
688690
ト変数およびメソッドを宣言できる。これにより、多くの言語、特に Java で頻繁に行
689691
われる、インターフェイスを個別に指定する必要がなくなった。
690-
692+
TODO: 現時点では実装されていない。
691693

692694
クラス内の項目 ~
693695
*E1318* *E1325* *E1388*
@@ -728,24 +730,24 @@ Shape, Square および Triangle を使用した上記の例は、オブジェ
728730
使用できる。オブジェクトは、これらの組み込み関数と同じ名前のメソッドを実装し
729731
て、オブジェクト固有の値を返すことができる。
730732

731-
*E1412*
733+
*E1412*
732734
以下の組み込みメソッドがサポートされている:
733-
*object-empty()*
735+
*object-empty()*
734736
empty() |empty()| 関数によって呼び出され、オブジェクトが空かどうかを確認
735737
する。このメソッドが存在しない場合は、true が返される。このメソッ
736738
ドは引数を受け入れず、真偽値を返す必要がある。
737-
*object-len()*
739+
*object-len()*
738740
len() |len()| 関数によって呼び出され、オブジェクトの長さを返す。このメ
739741
ソッドがクラスにない場合はエラーが発生し、ゼロが返される。このメ
740742
ソッドは引数を受け入れず、数値を返す必要がある。
741-
*object-string()*
743+
*object-string()*
742744
string() |string()| 関数によって呼び出され、オブジェクトのテキスト表現を取
743745
得する。オブジェクトに対する |:echo| コマンドでも使用される。この
744746
メソッドがクラスにない場合は、組み込みのデフォルトのテキスト表現
745747
が使用される。このメソッドは引数を受け入れず、文字列を返す必要が
746748
ある。
747749

748-
*E1413*
750+
*E1413*
749751
クラスメソッドを組み込みメソッドとして使用することはできない。
750752

751753
インターフェイスの定義 ~
@@ -777,7 +779,6 @@ Shape, Square および Triangle を使用した上記の例は、オブジェ
777779
インターフェイスは他のインターフェイスを "implement" することはできないが、他
778780
のインターフェイスを "extend" することはできる。 *E1381*
779781

780-
781782
null オブジェクト ~
782783

783784
変数がオブジェクトの型を持つように宣言されているが初期化されていない場合、値は
@@ -786,7 +787,6 @@ null になる。この null オブジェクトを使用しようとすると、
786787
正しいかどうかをチェックできず、変数名が無効な場合でも "Using a null object"
787788
エラーが発生する。 *E1360* *E1362*
788789

789-
790790
デフォルトコンストラクタ ~
791791
*default-constructor*
792792
new() メソッドを使用せずにクラスを定義した場合は、自動的に new() メソッドが定
@@ -1100,7 +1100,6 @@ TypeScript などの他の言語では、"constructor()" 等の特定の名前
11001100
トは正しい選択であるように思えた。これを new() と呼び出すことで、呼び出し元と
11011101
呼び出されるメソッドの関係が明確になる。
11021102

1103-
11041103
コンストラクタのオーバーロードを行わない ~
11051104

11061105
Vim script では、旧来と |Vim9| の両スクリプトとも、メソッドのオーバーロードは
@@ -1119,15 +1118,13 @@ Vim script では、旧来と |Vim9| の両スクリプトとも、メソッド
11191118
のコンストラクタが使用されているかを確認するのが非常に簡単になる。引数の型も適
11201119
切に確認できる。
11211120

1122-
11231121
メソッドのオーバーロードを行わない ~
11241122

11251123
コンストラクタの場合と同じ理由である。多くの場合、引数の型が明らかではないた
11261124
め、実際にどのメソッドが呼び出されているかを把握することが困難になる。メソッド
11271125
に別の名前を付けるだけで、型チェックによって意図したとおりに動作することが確認
11281126
される。これにより、実際には必要のないポリモーフィズムが排除される。
11291127

1130-
11311128
単一の継承とインターフェイス ~
11321129

11331130
一部の言語は多重継承をサポートしている。これは場合によっては便利だが、クラスの
@@ -1142,7 +1139,6 @@ Vim script では、旧来と |Vim9| の両スクリプトとも、メソッド
11421139
たま一致したからといって、クラスがインターフェイスを実装しているとみなすメカニ
11431140
ズムは脆弱で、分かりにくい問題を引き起こすため、やめておこう。
11441141

1145-
11461142
あらゆる場所で "this.variable" を使用する ~
11471143

11481144
さまざまなプログラミング言語のオブジェクト変数には、多くの場合、場所に応じてさ
@@ -1160,7 +1156,6 @@ Vim script では、旧来と |Vim9| の両スクリプトとも、メソッド
11601156
使用される。シンプルで一貫性がある。クラス内部のコードを見る時にも、どの変数参
11611157
照がオブジェクト変数で、どれがそうでないかが直接明らかになる。
11621158

1163-
11641159
クラス変数の使用 ~
11651160

11661161
"static variable" を使ってクラス変数を宣言するのはよくあることで、特に目新しい
@@ -1173,7 +1168,6 @@ TypeScript は、クラス内でもクラス変数名の前にクラス名を付
11731168
問題がある: クラス名はかなり長くなり、かなりのスペースが必要になることと、クラ
11741169
ス名が変更されたときに、これらの場所もすべて変更する必要があることだ。
11751170

1176-
11771171
オブジェクト変数とクラス変数の宣言 ~
11781172

11791173
主な選択肢は、変数宣言のように "var" を使うかどうかである。TypeScript では使用
@@ -1226,7 +1220,6 @@ Vim のオブジェクト変数は以下のように宣言できる: >
12261220
を再利用している。そのため、一貫性を保つために、これらの宣言では "var" を必要
12271221
とする。
12281222

1229-
12301223
"ClassName.new()" を使用してオブジェクトを構築する ~
12311224

12321225
多くの言語では、オブジェクトの作成に "new" 演算子を使用するが、コンストラクタ
@@ -1291,7 +1284,6 @@ Vim9class でサポートされる変数アクセスモードとその意味は
12911284
"protected" キーワードを使用することもできる。まぁ、これはキーワードの数を減ら
12921285
すためなのだが。
12931286

1294-
12951287
オブジェクト変数に private はない ~
12961288

12971289
一部の言語では、オブジェクト変数へのアクセスを制御するいくつかの方法が提供され

en/vim9class.txt

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*vim9class.txt* For Vim version 9.1. Last change: 2024 Dec 29
1+
*vim9class.txt* For Vim version 9.1. Last change: 2025 Feb 16
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -52,7 +52,6 @@ An interface is used to specify properties of an object:
5252
The class hierarchy allows for single inheritance. Otherwise interfaces are
5353
to be used where needed.
5454

55-
5655
Class modeling ~
5756

5857
You can model classes any way you like. Keep in mind what you are building,
@@ -122,7 +121,6 @@ using the object name followed by a dot following by the member: >
122121
A class name cannot be used as an expression. A class name cannot be used in
123122
the left-hand-side of an assignment.
124123

125-
126124
Object variable write access ~
127125
*read-only-variable*
128126
Now try to change an object variable directly: >
@@ -272,6 +270,9 @@ no need to call "super()" or "new()" on the parent.
272270
When defining the new() method the return type should not be specified. It
273271
always returns an object of the class.
274272

273+
The new() method can be made a protected method by using "_new()". This can
274+
be used to support the singleton design pattern.
275+
275276
*E1386*
276277
When invoking an object method, the method name should be preceded by the
277278
object variable name. An object method cannot be invoked using the class
@@ -623,13 +624,15 @@ once. They can appear in any order, although this order is recommended: >
623624
extends ClassName
624625
implements InterfaceName, OtherInterface
625626
specifies SomeInterface
626-
< *E1355* *E1369*
627+
<
628+
The "specifies" feature is currently not implemented.
629+
630+
*E1355* *E1369*
627631
Each variable and method name can be used only once. It is not possible to
628632
define a method with the same name and different type of arguments. It is not
629633
possible to use a public and protected member variable with the same name. An
630634
object variable name used in a super class cannot be reused in a child class.
631635

632-
633636
Object Variable Initialization ~
634637

635638
If the type of a variable is not explicitly specified in a class, then it is
@@ -686,13 +689,12 @@ A class can implement one or more interfaces. The "implements" keyword can
686689
only appear once *E1350* . Multiple interfaces can be specified, separated by
687690
commas. Each interface name can appear only once. *E1351*
688691

689-
690692
A class defining an interface ~
691693
*specifies*
692694
A class can declare its interface, the object variables and methods, with a
693695
named interface. This avoids the need for separately specifying the
694696
interface, which is often done in many languages, especially Java.
695-
697+
TODO: This is currently not implemented.
696698

697699
Items in a class ~
698700
*E1318* *E1325* *E1388*
@@ -733,25 +735,25 @@ Some of the builtin functions like |empty()|, |len()| and |string()| can be
733735
used with an object. An object can implement a method with the same name as
734736
these builtin functions to return an object-specific value.
735737

736-
*E1412*
738+
*E1412*
737739
The following builtin methods are supported:
738-
*object-empty()*
740+
*object-empty()*
739741
empty() Invoked by the |empty()| function to check whether an object is
740742
empty. If this method is missing, then true is returned. This
741743
method should not accept any arguments and must return a boolean.
742-
*object-len()*
744+
*object-len()*
743745
len() Invoked by the |len()| function to return the length of an
744746
object. If this method is missing in the class, then an error is
745747
given and zero is returned. This method should not accept any
746748
arguments and must return a number.
747-
*object-string()*
749+
*object-string()*
748750
string() Invoked by the |string()| function to get a textual
749751
representation of an object. Also used by the |:echo| command
750752
for an object. If this method is missing in the class, then a
751753
built-in default textual representation is used. This method
752754
should not accept any arguments and must return a string.
753755

754-
*E1413*
756+
*E1413*
755757
A class method cannot be used as a builtin method.
756758

757759
Defining an interface ~
@@ -783,7 +785,6 @@ An interface can only be defined in a |Vim9| script file. *E1342*
783785
An interface cannot "implement" another interface but it can "extend" another
784786
interface. *E1381*
785787

786-
787788
null object ~
788789

789790
When a variable is declared to have the type of an object, but it is not
@@ -792,7 +793,6 @@ does not know what class was supposed to be used. Vim then cannot check if
792793
a variable name is correct and you will get a "Using a null object" error,
793794
even when the variable name is invalid. *E1360* *E1362*
794795

795-
796796
Default constructor ~
797797
*default-constructor*
798798
In case you define a class without a new() method, one will be automatically
@@ -1115,7 +1115,6 @@ For |Vim9| script using the same method name for all constructors seemed like
11151115
the right choice, and by calling it new() the relation between the caller and
11161116
the method being called is obvious.
11171117

1118-
11191118
No overloading of the constructor ~
11201119

11211120
In Vim script, both legacy and |Vim9| script, there is no overloading of
@@ -1136,7 +1135,6 @@ That way multiple constructors with different arguments are possible, while it
11361135
is very easy to see which constructor is being used. And the type of
11371136
arguments can be properly checked.
11381137

1139-
11401138
No overloading of methods ~
11411139

11421140
Same reasoning as for the constructor: It is often not obvious what type
@@ -1145,7 +1143,6 @@ actually being called. Better just give the methods a different name, then
11451143
type checking will make sure it works as you intended. This rules out
11461144
polymorphism, which we don't really need anyway.
11471145

1148-
11491146
Single inheritance and interfaces ~
11501147

11511148
Some languages support multiple inheritance. Although that can be useful in
@@ -1161,7 +1158,6 @@ it will be checked if that change was also changed. The mechanism to assume a
11611158
class implements an interface just because the methods happen to match is
11621159
brittle and leads to obscure problems, let's not do that.
11631160

1164-
11651161
Using "this.variable" everywhere ~
11661162

11671163
The object variables in various programming languages can often be accessed in
@@ -1180,7 +1176,6 @@ variables. Simple and consistent. When looking at the code inside a class
11801176
it's also directly clear which variable references are object variables and
11811177
which aren't.
11821178

1183-
11841179
Using class variables ~
11851180

11861181
Using "static variable" to declare a class variable is very common, nothing
@@ -1194,7 +1189,6 @@ the class. This has two problems: The class name can be rather long, taking
11941189
up quite a bit of space, and when the class is renamed all these places need
11951190
to be changed too.
11961191

1197-
11981192
Declaring object and class variables ~
11991193

12001194
The main choice is whether to use "var" as with variable declarations.
@@ -1248,7 +1242,6 @@ function declaration syntax for class/object variables and methods. Vim9 also
12481242
reuses the general function declaration syntax for methods. So, for the sake
12491243
of consistency, we require "var" in these declarations.
12501244

1251-
12521245
Using "ClassName.new()" to construct an object ~
12531246

12541247
Many languages use the "new" operator to create an object, which is actually
@@ -1312,7 +1305,6 @@ An alternative would have been using the "protected" keyword, just like
13121305
"public" changes the access in the other direction. Well, that's just to
13131306
reduce the number of keywords.
13141307

1315-
13161308
No private object variables ~
13171309

13181310
Some languages provide several ways to control access to object variables.

0 commit comments

Comments
 (0)