You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello. I want to extend existing method when extending a class (just add a new function to it, not owerwrite), but don't know how to do it. Here is an example:
localObject=require"classic"localA=Object:extend()
functionA:new()
functionself.sayHi()
print("Hi from A!")
endendlocalB=A:extend()
functionB:new()
B.super.new(self)
functionself.sayHi()
-- B.super.sayHi() -- not workingprint("Hi from B!") -- overwritesendendlocalb=B()
b.sayHi() -- Hi from B only!
The text was updated successfully, but these errors were encountered:
Methods should be declared outside of the new function and should use : instead of . when created and called. When calling a super method self should be passed to it:
localObject=require"classic"localA=Object:extend()
functionA:new()
endfunctionA:sayHi()
print("Hi from A!")
endlocalB=A:extend()
functionB:new()
B.super.new(self)
endfunctionB:sayHi()
B.super.sayHi(self)
print("Hi from B!")
endlocalb=B()
b:sayHi()
-- prints:-- Hi from A!-- Hi from B!
Hello. I want to extend existing method when extending a class (just add a new function to it, not owerwrite), but don't know how to do it. Here is an example:
The text was updated successfully, but these errors were encountered: