YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

access this from inner table.
mariusco
#1 Posted : Wednesday, July 11, 2018 1:51:20 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 7/11/2018(UTC)
Posts: 5
Location: toronto

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
How do I access the instance from inner table function ?
Explicit:
- how do I call basefoo from do_some, passing parent class instance

Code:


class Base
{
    function basefoo(inst)
    {
        print (inst.var1);
    }    
}



class FromBase extends Base
{

    some =
    {
        var1="asdfasd",
        function operate()
        {
            // I dont wnt to pass this.
            // how do I call Base::basefoo  passing some, or FromBase::this
        },        
        function operate_with_o(obj)
        {
            obj.basefoo(this);   // OK
        }        
    
    }


    function do_some()
    {
        some.operate_with_o(this);   // I dont want to pass this...
    }



}

absence
#2 Posted : Monday, July 16, 2018 8:11:10 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 8/23/2014(UTC)
Posts: 127
Man
Location: Northern Germany & Lincolnshire, U.K.

Thanks: 2 times
Was thanked: 10 time(s) in 10 post(s)

see keyword "base"

e.g. base.basefoo();

(Hence, a confusing approach to actually call a class "Base" like you did in your example ;-)
VoidSpirit
#3 Posted : Saturday, July 21, 2018 6:07:11 PM(UTC)
Rank: Member

Groups: Registered
Joined: 12/27/2016(UTC)
Posts: 10

Thanks: 0 times
Was thanked: 2 time(s) in 2 post(s)
Try to use environment binding for 'operate' in class constructor:
constructor()
{some={
var1="asdfasd";
function operate()
{...
}
...
};
some.operate=some.operate.bindenv(this);
}
Remember, you have to create table in the constructor so every instance have own table and it's functions.
But so you'll not can use table's data in 'operate' - 'this' will be replaced.
simonsilverport
#4 Posted : Monday, September 24, 2018 2:15:43 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 9/24/2018(UTC)
Posts: 6
Location: USA

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
nice
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Clean Slate theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.119 seconds.