summaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-12-13 18:43:22 +0000
committerBram Moolenaar <Bram@vim.org>2022-12-13 18:43:22 +0000
commit65b0d1676814ee08fb58ef8d64dd342d1d883192 (patch)
tree4fbd70e4211e702a5212c717fe09636222f23026 /runtime
parent692fe0889c44d97c4a1cc822bc8de189859c51cb (diff)
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')
-rw-r--r--runtime/doc/vim9class.txt16
1 files changed, 10 insertions, 6 deletions
diff --git a/runtime/doc/vim9class.txt b/runtime/doc/vim9class.txt
index 7785fbe130..4dc84f3efc 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 ~