Skip to content

Commit 726398b

Browse files
authored
Merge pull request #1828 from h-east/update-vim9class
Update vim9class.{txt,jax}
2 parents 507375f + 54e20de commit 726398b

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

doc/vim9class.jax

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*vim9class.txt* For Vim バージョン 9.1. Last change: 2024 Apr 13
1+
*vim9class.txt* For Vim バージョン 9.1. Last change: 2024 Nov 11
22

33

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

867+
オブジェクトに変数型 "any" を使用する ~
868+
*obj-var-type-any*
869+
オブジェクトを保持するために、"any" 型で宣言された変数を使用できる。例:
870+
>
871+
vim9script
872+
class A
873+
var n = 10
874+
def Get(): number
875+
return this.n
876+
enddef
877+
endclass
878+
879+
def Fn(o: any)
880+
echo o.n
881+
echo o.Get()
882+
enddef
883+
884+
var a = A.new()
885+
Fn(a)
886+
<
887+
この例では、Vim はコンパイル時に関数 Fn() のパラメータ "o" の型を判別できない。
888+
|Dict| または |Object| 値のいずれかになる。したがって、実行時に型がわかってい
889+
る場合は、オブジェクトメンバー変数とメソッドが検索される。この処理過程は効率的
890+
ではないため、効率を高めるために可能な限りより具体的な型を使用することをお勧め
891+
する。
892+
867893
クラス内のメソッドをコンパイルする ~
868894
*class-compile*
869895
|:defcompile| コマンドを使用すると、クラスで定義されているすべてのクラスメソッ

en/vim9class.txt

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*vim9class.txt* For Vim version 9.1. Last change: 2024 Apr 13
1+
*vim9class.txt* For Vim version 9.1. Last change: 2024 Nov 11
22

33

44
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
873873
"new()" then the default constructor is added, even though there are other
874874
constructor methods.
875875

876+
Using variable type "any" for an Object~
877+
*obj-var-type-any*
878+
You can use a variable declared with type "any" to hold an object. e.g.
879+
>
880+
vim9script
881+
class A
882+
var n = 10
883+
def Get(): number
884+
return this.n
885+
enddef
886+
endclass
887+
888+
def Fn(o: any)
889+
echo o.n
890+
echo o.Get()
891+
enddef
892+
893+
var a = A.new()
894+
Fn(a)
895+
<
896+
In this example, Vim cannot determine the type of the parameter "o" for
897+
function Fn() at compile time. It can be either a |Dict| or an |Object|
898+
value. Therefore, at runtime, when the type is known, the object member
899+
variable and method are looked up. This process is not efficient, so it is
900+
recommended to use a more specific type whenever possible for better
901+
efficiency.
902+
876903
Compiling methods in a Class ~
877904
*class-compile*
878905
The |:defcompile| command can be used to compile all the class and object

0 commit comments

Comments
 (0)