diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-12-13 18:43:22 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-12-13 18:43:22 +0000 |
commit | 65b0d1676814ee08fb58ef8d64dd342d1d883192 (patch) | |
tree | 4fbd70e4211e702a5212c717fe09636222f23026 /runtime/doc | |
parent | 692fe0889c44d97c4a1cc822bc8de189859c51cb (diff) | |
download | vim-git-65b0d1676814ee08fb58ef8d64dd342d1d883192.tar.gz |
patch 9.0.1053: default constructor arguments are not optionalv9.0.1053
Problem: Default constructor arguments are not optional.
Solution: Use "= v:none" to make constructor arguments optional.
Diffstat (limited to 'runtime/doc')
-rw-r--r-- | runtime/doc/vim9class.txt | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/runtime/doc/vim9class.txt b/runtime/doc/vim9class.txt index 7785fbe13..4dc84f3ef 100644 --- a/runtime/doc/vim9class.txt +++ b/runtime/doc/vim9class.txt @@ -431,15 +431,15 @@ members, in the order they were specified. Thus if your class looks like: > Then The default constructor will be: > - def new(this.name = void, this.age = void, this.gender = void) + def new(this.name = v:none, this.age = v:none, this.gender = v:none) enddef All object members will be used, also private access ones. -The "= void" default values make the arguments optional. Thus you can also -call `new()` without any arguments. Since "void" isn't an actual value, no -assignment will happen and the default value for the object members will be -used. This is a more useful example, with default values: > +The "= v:none" default values make the arguments optional. Thus you can also +call `new()` without any arguments. No assignment will happen and the default +value for the object members will be used. This is a more useful example, +with default values: > class TextPosition this.lnum: number = 1 @@ -450,8 +450,12 @@ If you want the constructor to have mandatory arguments, you need to write it yourself. For example, if for the AutoNew class above you insist on getting the name, you can define the constructor like this: > - def new(this.name, this.age = void, this.gender = void) + def new(this.name, this.age = v:none, this.gender = v:none) enddef +< *E1328* +Note that you cannot use another default value than "v:none" here. If you +want to initialize the object members, do it where they are declared. This +way you only need to look in one place for the default values. Multiple constructors ~ |