Ok, here are some notes after sleeping with this:
Inside a method, the pseudo-keyword base can be used to access the super-class versions of methods or properties which are overridden in a derived class.
Perhaps the word 'invoke' would be better - 'invoke' was used before in the documentation.
For example, base.Method() in the class defined above would call the version of Method which is defined by BaseClassName.
So the assumption here is that BCN has the method defined. If the assumption should not be made, perhaps something like this could be added: "possibly defined by BCN or one of its super-classes".
Meta-functions are not called; otherwise, base.Method() behaves like BaseClassName.Method.(this).
Here, I'd say there could be two choices - either leave the revised version of the documentation as it is (and not compare
base.Method to
this.base.base.Method() at all - it seems hard to come up with a 'clear' description of
BCN.Method.(this) /
this.base.base.Method() /
base.Method() in just one sentence):
That is,
- base.Method() always invokes the base of the class where the current method was defined, even if this is derived from a sub-class of that class or some other class entirely.
- base.Method() implicitly passes this as the first (hidden) parameter.
or perhaps create a table comparing all three, in terms of:
- calls meta-functions
- always invokes base of _current_ class
- uses this as first parameter.
That would mean the duplication of information about meta-functions in trade of the table depicting everything separately. But perhaps conciseness is more valued and
this.base.base.Method() shouldn't be mentioned at all (or just mentioned that it's there, somewhere at the end).
Meta-functions are not called; otherwise, base.Method() behaves like BaseClassName.Method.(this).
Lexikos wrote:The comparison between base.Method() and this.base.base.Method() is mostly an unneeded distraction, trying to explain why the latter should not be used. What should be written is just how base.Method() actually behaves.
Yes, I agree that
base.Method() should be compared mainly to
BaseClassName.Method.(this) (vs to
this.base.base.Method()). The syntax of
BaseClassName.Method.(this) denotes clearly, that it is the
__Get (vs
__Call) operation. The same is true for Properties:
base.Method() does call the _Get_ half-property (~there is no Call property).
After testing if
base.Method() behaves exactly like
BCN.Method.(this) with:
- function references
- function names
- functors
- Properties,
there seems to be a difference with functors: (in params passed to
__Call of the functor)
Code: Select all
class Properties {
__Call(aP*) {
msgbox, % "param count: " (aP.MaxIndex() = "" ? 0 : ap.MaxIndex())
. "`n" (IsObject(aP[1]) ? "<Object>" : "|" aP "|")
. "`n" (IsObject(aP[2]) ? "<Object>" : "|" aP "|")
. "`n" (IsObject(aP[3]) ? "<Object>" : "|" aP "|")
}
}
class dx {
static Method := {base: Properties}
}
class cx extends dx {
Method() {
msgbox cx_method
;base.Method() ; switch those
; 1 - Object
dx.Method.(this)
; 1 - ""
; 2 - Object()
}
}
x := new cx()
x.Method()
I also like the idea of splitting this discussion into a separate topic, i.e.: "base pseudo-keyword inside of method - documentation" or sth similar.