Re: Self parameter
Posted: Thu Jun 28, 2012 11:05 pm
I made a mistake in the previuos post, well the answer is that this way I'm able to create new objects from objects, see below what I mean:
This way the original class is untouched and I'm able to override any existing properties because the TB.Set() used in the New method.
Code: Select all
myClass = { x = 0, y = 0 }
Function myClass:New(parameters)
Local NewObj = CopyTable(self) ; <--- here is where I've made the mistake in the previous post
TB.Set(NewObj, parameters, False)
Return(NewObj)
EndFunction
Local myObject = myClass:New()
; Now I can derivate objects from the one we have just created
; but I want more properties
myObject.z = 1
myObject.k = 0.5
; New object based on myObject
myDerivedObject = myObject:New({ z = 10 })