forked from aniani/vim
patch 9.0.1804: Vim9: no support for private object methods
Problem: Vim9: no support for private object methods Solution: Add support for private object/class methods closes: #12920 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
committed by
Christian Brabandt
parent
03e44a1d70
commit
cd7293bf6c
@@ -129,6 +129,7 @@ Further Vim9 improvements, possibly after launch:
|
||||
or: def _Func()
|
||||
Perhaps use "private" keyword instead of "_" prefix?
|
||||
- "final" object members - can only be set in the constructor.
|
||||
- Support export/import of classes and interfaces.
|
||||
- Cannot use class type of itself in the method (Issue #12369)
|
||||
- Cannot use an object method in a lambda #12417
|
||||
Define all methods before compiling them?
|
||||
|
@@ -178,6 +178,26 @@ number to the total number of lines: >
|
||||
enddef
|
||||
|
||||
|
||||
Private methods ~
|
||||
If you want object methods to be accessible only from other methods of the
|
||||
same class and not used from outside the class, then you can make them
|
||||
private. This is done by prefixing the method name with an underscore: >
|
||||
|
||||
class SomeClass
|
||||
def _Foo(): number
|
||||
return 10
|
||||
enddef
|
||||
def Bar(): number
|
||||
return this._Foo()
|
||||
enddef
|
||||
endclass
|
||||
<
|
||||
Accessing a private method outside the class will result in an error (using
|
||||
the above class): >
|
||||
|
||||
var a = SomeClass.new()
|
||||
a._Foo()
|
||||
<
|
||||
Simplifying the new() method ~
|
||||
|
||||
Many constructors take values for the object members. Thus you very often see
|
||||
@@ -284,6 +304,18 @@ object members, they cannot use the "this" keyword. >
|
||||
Inside the class the function can be called by name directly, outside the
|
||||
class the class name must be prefixed: `OtherThing.ClearTotalSize()`.
|
||||
|
||||
Just like object methods the access can be made private by using an underscore
|
||||
as the first character in the method name: >
|
||||
|
||||
class OtherThing
|
||||
static def _Foo()
|
||||
echo "Foo"
|
||||
enddef
|
||||
def Bar()
|
||||
OtherThing._Foo()
|
||||
enddef
|
||||
endclass
|
||||
|
||||
==============================================================================
|
||||
|
||||
4. Using an abstract class *Vim9-abstract-class*
|
||||
|
Reference in New Issue
Block a user