Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update vim9class.{txt,jax} #1490

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions doc/vim9class.jax
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*vim9class.txt* For Vim バージョン 9.1. Last change: 2024 Mar 28
*vim9class.txt* For Vim バージョン 9.1. Last change: 2024 Apr 13


VIMリファレンスマニュアル by Bram Moolenaar
Expand Down Expand Up @@ -323,10 +323,28 @@ new() メソッドを定義するときは、戻り値の型を指定しない
enddef
endclass

クラス内ではクラスメソッドを名前で直接呼び出すことができるが、クラスの外ではク
ラス名はプリフィックス付きである必要がある: `OtherThing.ClearTotalSize()`。親
クラスのクラスメソッドを子クラスで使用するには、クラス名をプリフィックスとして
付ける必要がある。
クラス内では、クラスメソッドを名前で直接呼び出すことができるが、クラスの外で
は、クラス名がプリフィックスされている必要がある:
`OtherThing.ClearTotalSize()`。また、クラス変数初期化子、ラムダ式、入れ子になっ
た関数といった特殊なコンテキストでは、パブリッククラスメソッドに名前プリフィッ
クスを使用しなければならない:
>
class OtherThing
static var name: string = OtherThing.GiveName()

static def GiveName(): string
def DoGiveName(): string
return OtherThing.NameAny()
enddef

return DoGiveName()
enddef

static def NameAny(): string
return "any"
enddef
endclass
<

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

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

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

*enum-name*
各列挙値オブジェクトには、列挙値の名前を含む "name" インスタンス変数がある。こ
Expand Down
33 changes: 25 additions & 8 deletions en/vim9class.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*vim9class.txt* For Vim version 9.1. Last change: 2024 Mar 28
*vim9class.txt* For Vim version 9.1. Last change: 2024 Apr 13


VIM REFERENCE MANUAL by Bram Moolenaar
Expand Down Expand Up @@ -328,10 +328,27 @@ variables but they have no access to the object variables, they cannot use the
enddef
endclass

Inside the class the class method can be called by name directly, outside the
class the class name must be prefixed: `OtherThing.ClearTotalSize()`. To use
a class method from a parent class in a child class, the class name must be
prefixed.
Inside the class, the class method can be called by name directly, outside the
class, the class name must be prefixed: `OtherThing.ClearTotalSize()`. Also,
the name prefix must be used for public class methods in the special contexts
of class variable initializers and of lambda expressions and nested functions:
>
class OtherThing
static var name: string = OtherThing.GiveName()

static def GiveName(): string
def DoGiveName(): string
return OtherThing.NameAny()
enddef

return DoGiveName()
enddef

static def NameAny(): string
return "any"
enddef
endclass
<

Just like object methods the access can be made protected by using an
underscore as the first character in the method name: >
Expand Down Expand Up @@ -576,7 +593,7 @@ A class is defined between `:class` and `:endclass`. The whole class is
defined in one script file. It is not possible to add to a class later.

A class can only be defined in a |Vim9| script file. *E1316*
A class cannot be defined inside a function.
A class cannot be defined inside a function. *E1429*

It is possible to define more than one class in a script file. Although it
usually is better to export only one main class. It can be useful to define
Expand Down Expand Up @@ -972,8 +989,8 @@ The following example shows an enum with object variables and methods: >
echo Planet.Earth.has_rings
<
*E1421* *E1423* *E1424* *E1425*
Enums and their values are immutable. They cannot be modified after
declaration and cannot be utilized as numerical or string types.
Enums and their values are immutable. They cannot be utilized as numerical or
string types. Enum values can declare mutable instance variables.

*enum-name*
Each enum value object has a "name" instance variable which contains the name
Expand Down