You’ve read that wrong. It is returning the result of a conditional check, it isn’t returning the elements in the condition. e.g. It is not returning obj.removeSelf
, instead it is checking if obj.removeSelf
exists.
Let me break it down
return ( obj and obj.removeSelf and type(obj.removeSelf) == "function" )
left to right.
- return
false
if obj is nil
- return
false
if obj.removeSelf (handle to function) does not exists (is nil
)
- return
false
if obj.removeSelf handle is present, but does not reference a function.
The obj
is nil case should be pretty clear, but what about the other two?
When you delete a display object, the object handle obj
is cleaned up. In that cleaning, all references to functions are removed. Thus, the second check above.
The last check is a bit over-the-top, but protects you from the weird case where obj exists and it has a field named removeSelf
, but removeSelf
is not a function. i.e. This is not a display object.