Improved for code to make it 'more' correct for Basereality objects.

Fixed '$this->someFunction()' not having 'this.' in generated code.
Made new 'self' work.
Added state for extend - needs to bring in other class.