Ok, I got. Since you didn't answer the questions from my next message I take it as there is no way to apply a class's method to an object that was created not by an instance of a class.lexikos wrote:You asked:In that case, newobj is already an instance of myClass and you can just call one of its normal methods, as I said.can I use the same newobj := new myClass() [...]?
I hoped that classes could be used like that:
Code: Select all
myObject := new myClass()
myObject := ["a", "b"]
myObject.myMethod() ; it should become ["a", "b", "c"], but instead it's ["a", "b"]. If one swaps first two lines - the result becomes ["c"].
class myClass
{
myMethod()
{
this.Push("c")
}
}
Code: Select all
myRealObject := ["a", "b"]
myFakeObject := new myClass() ; a wasted variable.
myFakeObject.myMethod(myRealObject)
MsgBox, % (myRealObject.MaxIndex() == 3 ? "true" : "false" ) ; true, myRealObject is now ["a", "b", "c"]
class myClass
{
myMethod(input)
{
input.Push("c")
}
}
Code: Select all
myObject := ["a", "b"]
myFunction(myObject)
MsgBox, % (myObject.MaxIndex() == 3 ? "true" : "false" ) ; true, myRealObject is now ["a", "b", "c"]
myFunction(ByRef input)
{
input.Push("c")
}
Code: Select all
...
class myClass
{
__New()
{
this.Push("a", "b") ; by the way, I'd use here 'this := ["a", "b"]' instead, but that won't work.
}
...