overriding inherited property with value Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
sirksel
Posts: 222
Joined: 12 Nov 2013, 23:48

overriding inherited property with value

05 Sep 2020, 08:15

I know one can override a calculated property in a subclass by simply redefining the calculated property. Is there any way to revert back from a calculated to non-calculated property (value property or member access or whatever the correct term is)? I've tried various ways, but I keep getting the "property is read-only error". I'm guessing there's a way to do this, but I haven't figured it out. Illustrative code below:

Code: Select all

class top {
  someprop => 'somecalc'
  ; and other features
}
class special extends top {
  someprop := ''
  __new(val) {
    this.someprop := val
  }  ;wants to override someprop but keep other features of top
}
s := special.new(10)
msgbox s.someprop
Any help would be much appreciated!
User avatar
FredOoo
Posts: 186
Joined: 07 May 2019, 21:58
Location: Paris

Re: overriding inherited property with value  Topic is solved

06 Sep 2020, 06:09

Code: Select all

class top {
  someprop => 'somecalc'
}

class special1 extends top {
  __new(val) {
    this._someprop := val
  }
  someprop => this._someprop
  test() => super.someprop ; if top.someprop is still there
}
print "== s1 =="
s1 := special1.new(10)
print s1.someprop   ; 10
print s1.test()     ; someprop

class special2 extends top {
  __new(val) {
    this.DefineProp( 'someprop', { Value: val } )
  }
  test() => super.someprop
}
print "== s2 ==" ; ★ no need of _someprop ★
s2 := special2.new(10)
print s2.someprop   ; 10
print s2.test()     ; someprop
print
(Alan Turing) « What would be the point of saying that A = B if it was really the same thing? »
(Albert Camus) « Misnaming things is to add to the misfortunes of the world. »

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: CrowexBR, Draken, ntepa, wineguy and 42 guests