From 54e20dec0a2703f35f6ff8e684526a84a7ec8c0c Mon Sep 17 00:00:00 2001 From: h-east Date: Fri, 15 Nov 2024 19:36:40 +0900 Subject: [PATCH] Update vim9class.{txt,jax} --- doc/vim9class.jax | 28 +++++++++++++++++++++++++++- en/vim9class.txt | 29 ++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/doc/vim9class.jax b/doc/vim9class.jax index d6eb75db2..af3a15b76 100644 --- a/doc/vim9class.jax +++ b/doc/vim9class.jax @@ -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 @@ -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| コマンドを使用すると、クラスで定義されているすべてのクラスメソッ diff --git a/en/vim9class.txt b/en/vim9class.txt index ef96aa907..a06c2c6e0 100644 --- a/en/vim9class.txt +++ b/en/vim9class.txt @@ -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 @@ -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