Skip to content

Update vim9class.{txt,jax} #1828

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

Merged
merged 1 commit into from
Nov 17, 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
28 changes: 27 additions & 1 deletion 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 Apr 13
*vim9class.txt* For Vim バージョン 9.1. Last change: 2024 Nov 11


VIMリファレンスマニュアル by Bram Moolenaar
Expand Down Expand Up @@ -864,6 +864,32 @@ Note メソッド名は "new" で始まる必要があることに注意。"new(
ない場合は、他のコンストラクタメソッドがあっても、デフォルトコンストラクタが追
加される。

オブジェクトに変数型 "any" を使用する ~
*obj-var-type-any*
オブジェクトを保持するために、"any" 型で宣言された変数を使用できる。例:
>
vim9script
class A
var n = 10
def Get(): number
return this.n
enddef
endclass

def Fn(o: any)
echo o.n
echo o.Get()
enddef

var a = A.new()
Fn(a)
<
この例では、Vim はコンパイル時に関数 Fn() のパラメータ "o" の型を判別できない。
|Dict| または |Object| 値のいずれかになる。したがって、実行時に型がわかってい
る場合は、オブジェクトメンバー変数とメソッドが検索される。この処理過程は効率的
ではないため、効率を高めるために可能な限りより具体的な型を使用することをお勧め
する。

クラス内のメソッドをコンパイルする ~
*class-compile*
|:defcompile| コマンドを使用すると、クラスで定義されているすべてのクラスメソッ
Expand Down
29 changes: 28 additions & 1 deletion 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 Apr 13
*vim9class.txt* For Vim version 9.1. Last change: 2024 Nov 11


VIM REFERENCE MANUAL by Bram Moolenaar
Expand Down Expand Up @@ -873,6 +873,33 @@ Note that the method name must start with "new". If there is no method called
"new()" then the default constructor is added, even though there are other
constructor methods.

Using variable type "any" for an Object~
*obj-var-type-any*
You can use a variable declared with type "any" to hold an object. e.g.
>
vim9script
class A
var n = 10
def Get(): number
return this.n
enddef
endclass

def Fn(o: any)
echo o.n
echo o.Get()
enddef

var a = A.new()
Fn(a)
<
In this example, Vim cannot determine the type of the parameter "o" for
function Fn() at compile time. It can be either a |Dict| or an |Object|
value. Therefore, at runtime, when the type is known, the object member
variable and method are looked up. This process is not efficient, so it is
recommended to use a more specific type whenever possible for better
efficiency.

Compiling methods in a Class ~
*class-compile*
The |:defcompile| command can be used to compile all the class and object
Expand Down