this, me and __this__

classic Classic list List threaded Threaded
40 messages Options
12
Reply | Threaded
Open this post in threaded view
|

this, me and __this__

Nicolas Cannasse
Hi list,

An important change that I want to make in haXe is to remove the need to
declare a "me" variable in order to access "this" in local functions:

class Foo {
   function bar() {
        var me = this;
        var callb = function() {
                trace(me);
        };
        // ...
   }
}

The idea is that you should be directly able to access "this" (and
this.vars) inside the local function.

However in order to reach that, we need to deal with inconsistencies
with other languages, in particular Javascript.

In JS (and Neko, and Flash), "this" already refer to the "current
object", which is NOT the object in which the local function is declared.

For instance :

class Foo {
   function bar() {
      var me = this;
      var o = { callb : function() trace(untyped this) };
      o.callb();
   }
}

In that case, JS/Neko/Flash behavior would be to have "this == o"
whereas the new haXe behavior would be "this == me"

Currently of course, haXe forbid you to access "this" in local
functions, because of that reason. But, you can still access it with
"untyped", which was used by several haXe std classes implementation in
order to access the "current object this".

So, in order to smooth transition, I have made the following change
(commited in r3864) : 'this' is no longer accessible in local functions,
even in 'untyped' mode. It has to be replaced by '__this__' (still in
'untyped' mode), which will identify the 'current this' and keep actual
behavior. This way we can track all these 'old this' usages and replace
them with '__this__'.

The next step will be to allow 'this' in local functions, this time not
only in untyped mode, but it will automatically create a "var me = this"
variable in the member method outside the local function.

That's it, hope some of you understood what I was talking about :)

Nicolas

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: this, me and __this__

Franco Ponticelli
Perfectly understandable and a very needed feature at least for me. I'll run my code to check for problems.

Thank you,

Franco

On Wed, Jul 27, 2011 at 1:15 PM, Nicolas Cannasse <[hidden email]> wrote:
Hi list,

An important change that I want to make in haXe is to remove the need to declare a "me" variable in order to access "this" in local functions:

class Foo {
 function bar() {
       var me = this;
       var callb = function() {
               trace(me);
       };
       // ...
 }
}

The idea is that you should be directly able to access "this" (and this.vars) inside the local function.

However in order to reach that, we need to deal with inconsistencies with other languages, in particular Javascript.

In JS (and Neko, and Flash), "this" already refer to the "current object", which is NOT the object in which the local function is declared.

For instance :

class Foo {
 function bar() {
    var me = this;
    var o = { callb : function() trace(untyped this) };
    o.callb();
 }
}

In that case, JS/Neko/Flash behavior would be to have "this == o" whereas the new haXe behavior would be "this == me"

Currently of course, haXe forbid you to access "this" in local functions, because of that reason. But, you can still access it with "untyped", which was used by several haXe std classes implementation in order to access the "current object this".

So, in order to smooth transition, I have made the following change (commited in r3864) : 'this' is no longer accessible in local functions, even in 'untyped' mode. It has to be replaced by '__this__' (still in 'untyped' mode), which will identify the 'current this' and keep actual behavior. This way we can track all these 'old this' usages and replace them with '__this__'.

The next step will be to allow 'this' in local functions, this time not only in untyped mode, but it will automatically create a "var me = this" variable in the member method outside the local function.

That's it, hope some of you understood what I was talking about :)

Nicolas

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: this, me and __this__

Alex Liebert
In reply to this post by Nicolas Cannasse
sounds like a good improvement, but i'm not sure I understand the last part.

What would we do in the meantime?

In your example:

class Foo {
 function bar() {
       var me = this;
       var callb = function() {
               trace(me);
       };
       // ...
 }

Is the only change to turn me = this to me = __this__?

Alex


On Wed, Jul 27, 2011 at 12:15 PM, Nicolas Cannasse <[hidden email]> wrote:
Hi list,

An important change that I want to make in haXe is to remove the need to declare a "me" variable in order to access "this" in local functions:

class Foo {
 function bar() {
       var me = this;
       var callb = function() {
               trace(me);
       };
       // ...
 }
}

The idea is that you should be directly able to access "this" (and this.vars) inside the local function.

However in order to reach that, we need to deal with inconsistencies with other languages, in particular Javascript.

In JS (and Neko, and Flash), "this" already refer to the "current object", which is NOT the object in which the local function is declared.

For instance :

class Foo {
 function bar() {
    var me = this;
    var o = { callb : function() trace(untyped this) };
    o.callb();
 }
}

In that case, JS/Neko/Flash behavior would be to have "this == o" whereas the new haXe behavior would be "this == me"

Currently of course, haXe forbid you to access "this" in local functions, because of that reason. But, you can still access it with "untyped", which was used by several haXe std classes implementation in order to access the "current object this".

So, in order to smooth transition, I have made the following change (commited in r3864) : 'this' is no longer accessible in local functions, even in 'untyped' mode. It has to be replaced by '__this__' (still in 'untyped' mode), which will identify the 'current this' and keep actual behavior. This way we can track all these 'old this' usages and replace them with '__this__'.

The next step will be to allow 'this' in local functions, this time not only in untyped mode, but it will automatically create a "var me = this" variable in the member method outside the local function.

That's it, hope some of you understood what I was talking about :)

Nicolas

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: this, me and __this__

Franco Ponticelli
Nops ... in the meanwhile you still have to declare me. What is changed is that in case you used "untyped this" in your code (referring to the function scope and not to the instance scope) you must use "untyped __this__" instead. This is a very low level usage of haXe and you may incur in that only in very specific cases.

Franco

On Wed, Jul 27, 2011 at 1:19 PM, Alex Liebert <[hidden email]> wrote:
sounds like a good improvement, but i'm not sure I understand the last part.

What would we do in the meantime?

In your example:

class Foo {
 function bar() {
       var me = this;
       var callb = function() {
               trace(me);
       };
       // ...
 }

Is the only change to turn me = this to me = __this__?

Alex


On Wed, Jul 27, 2011 at 12:15 PM, Nicolas Cannasse <[hidden email]> wrote:
Hi list,

An important change that I want to make in haXe is to remove the need to declare a "me" variable in order to access "this" in local functions:

class Foo {
 function bar() {
       var me = this;
       var callb = function() {
               trace(me);
       };
       // ...
 }
}

The idea is that you should be directly able to access "this" (and this.vars) inside the local function.

However in order to reach that, we need to deal with inconsistencies with other languages, in particular Javascript.

In JS (and Neko, and Flash), "this" already refer to the "current object", which is NOT the object in which the local function is declared.

For instance :

class Foo {
 function bar() {
    var me = this;
    var o = { callb : function() trace(untyped this) };
    o.callb();
 }
}

In that case, JS/Neko/Flash behavior would be to have "this == o" whereas the new haXe behavior would be "this == me"

Currently of course, haXe forbid you to access "this" in local functions, because of that reason. But, you can still access it with "untyped", which was used by several haXe std classes implementation in order to access the "current object this".

So, in order to smooth transition, I have made the following change (commited in r3864) : 'this' is no longer accessible in local functions, even in 'untyped' mode. It has to be replaced by '__this__' (still in 'untyped' mode), which will identify the 'current this' and keep actual behavior. This way we can track all these 'old this' usages and replace them with '__this__'.

The next step will be to allow 'this' in local functions, this time not only in untyped mode, but it will automatically create a "var me = this" variable in the member method outside the local function.

That's it, hope some of you understood what I was talking about :)

Nicolas

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: this, me and __this__

Baluta Cristian
In reply to this post by Alex Liebert
I learned to avoid local functions, but good to know about the change.


On Wed, Jul 27, 2011 at 10:19 PM, Alex Liebert <[hidden email]> wrote:
sounds like a good improvement, but i'm not sure I understand the last part.

What would we do in the meantime?

In your example:

class Foo {
 function bar() {
       var me = this;
       var callb = function() {
               trace(me);
       };
       // ...
 }

Is the only change to turn me = this to me = __this__?

Alex


On Wed, Jul 27, 2011 at 12:15 PM, Nicolas Cannasse <[hidden email]> wrote:
Hi list,

An important change that I want to make in haXe is to remove the need to declare a "me" variable in order to access "this" in local functions:

class Foo {
 function bar() {
       var me = this;
       var callb = function() {
               trace(me);
       };
       // ...
 }
}

The idea is that you should be directly able to access "this" (and this.vars) inside the local function.

However in order to reach that, we need to deal with inconsistencies with other languages, in particular Javascript.

In JS (and Neko, and Flash), "this" already refer to the "current object", which is NOT the object in which the local function is declared.

For instance :

class Foo {
 function bar() {
    var me = this;
    var o = { callb : function() trace(untyped this) };
    o.callb();
 }
}

In that case, JS/Neko/Flash behavior would be to have "this == o" whereas the new haXe behavior would be "this == me"

Currently of course, haXe forbid you to access "this" in local functions, because of that reason. But, you can still access it with "untyped", which was used by several haXe std classes implementation in order to access the "current object this".

So, in order to smooth transition, I have made the following change (commited in r3864) : 'this' is no longer accessible in local functions, even in 'untyped' mode. It has to be replaced by '__this__' (still in 'untyped' mode), which will identify the 'current this' and keep actual behavior. This way we can track all these 'old this' usages and replace them with '__this__'.

The next step will be to allow 'this' in local functions, this time not only in untyped mode, but it will automatically create a "var me = this" variable in the member method outside the local function.

That's it, hope some of you understood what I was talking about :)

Nicolas

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org



--
Băluță Cristian
http://ralcr.com
http://imagin.ro

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: this, me and __this__

Franco Ponticelli
In reply to this post by Nicolas Cannasse
I've updated my code and it doesn't work anymore ... I don't have instances of "untyped this" in the code but must be something related.
I'll try to dig deeper and find out.

Franco

On Wed, Jul 27, 2011 at 1:15 PM, Nicolas Cannasse <[hidden email]> wrote:
Hi list,

An important change that I want to make in haXe is to remove the need to declare a "me" variable in order to access "this" in local functions:

class Foo {
 function bar() {
       var me = this;
       var callb = function() {
               trace(me);
       };
       // ...
 }
}

The idea is that you should be directly able to access "this" (and this.vars) inside the local function.

However in order to reach that, we need to deal with inconsistencies with other languages, in particular Javascript.

In JS (and Neko, and Flash), "this" already refer to the "current object", which is NOT the object in which the local function is declared.

For instance :

class Foo {
 function bar() {
    var me = this;
    var o = { callb : function() trace(untyped this) };
    o.callb();
 }
}

In that case, JS/Neko/Flash behavior would be to have "this == o" whereas the new haXe behavior would be "this == me"

Currently of course, haXe forbid you to access "this" in local functions, because of that reason. But, you can still access it with "untyped", which was used by several haXe std classes implementation in order to access the "current object this".

So, in order to smooth transition, I have made the following change (commited in r3864) : 'this' is no longer accessible in local functions, even in 'untyped' mode. It has to be replaced by '__this__' (still in 'untyped' mode), which will identify the 'current this' and keep actual behavior. This way we can track all these 'old this' usages and replace them with '__this__'.

The next step will be to allow 'this' in local functions, this time not only in untyped mode, but it will automatically create a "var me = this" variable in the member method outside the local function.

That's it, hope some of you understood what I was talking about :)

Nicolas

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: this, me and __this__

Nicolas Cannasse
In reply to this post by Franco Ponticelli
Le 27/07/2011 21:23, Franco Ponticelli a écrit :
> Nops ... in the meanwhile you still have to declare me. What is changed
> is that in case you used "untyped this" in your code (referring to the
> function scope and not to the instance scope) you must use "untyped
> __this__" instead. This is a very low level usage of haXe and you may
> incur in that only in very specific cases.

Thank you Franco for making things much more clear than I did :)

Nicolas

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: this, me and __this__

Franco Ponticelli
In reply to this post by Franco Ponticelli
Sorry my bad, the code is working perfectly fine and the error message is exactly where was supposed to be. I thought I had compiled the compiler but I didn't.
So far so good ;)

Franco

On Wed, Jul 27, 2011 at 1:26 PM, Franco Ponticelli <[hidden email]> wrote:
I've updated my code and it doesn't work anymore ... I don't have instances of "untyped this" in the code but must be something related.
I'll try to dig deeper and find out.

Franco


On Wed, Jul 27, 2011 at 1:15 PM, Nicolas Cannasse <[hidden email]> wrote:
Hi list,

An important change that I want to make in haXe is to remove the need to declare a "me" variable in order to access "this" in local functions:

class Foo {
 function bar() {
       var me = this;
       var callb = function() {
               trace(me);
       };
       // ...
 }
}

The idea is that you should be directly able to access "this" (and this.vars) inside the local function.

However in order to reach that, we need to deal with inconsistencies with other languages, in particular Javascript.

In JS (and Neko, and Flash), "this" already refer to the "current object", which is NOT the object in which the local function is declared.

For instance :

class Foo {
 function bar() {
    var me = this;
    var o = { callb : function() trace(untyped this) };
    o.callb();
 }
}

In that case, JS/Neko/Flash behavior would be to have "this == o" whereas the new haXe behavior would be "this == me"

Currently of course, haXe forbid you to access "this" in local functions, because of that reason. But, you can still access it with "untyped", which was used by several haXe std classes implementation in order to access the "current object this".

So, in order to smooth transition, I have made the following change (commited in r3864) : 'this' is no longer accessible in local functions, even in 'untyped' mode. It has to be replaced by '__this__' (still in 'untyped' mode), which will identify the 'current this' and keep actual behavior. This way we can track all these 'old this' usages and replace them with '__this__'.

The next step will be to allow 'this' in local functions, this time not only in untyped mode, but it will automatically create a "var me = this" variable in the member method outside the local function.

That's it, hope some of you understood what I was talking about :)

Nicolas

--
haXe - an open source web programming language
http://haxe.org



--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

RE: this, me and __this__

Lee Sylvester
In reply to this post by Nicolas Cannasse
Could we not borrow a leaf out of Lua's book?   In Lua (I forget the actual
syntax), but you can do something like this :-

public function someFunc() {
        this.x = 9;
        localFunc = function( this ) {
                this.x += 1;
        }
}

Of course, we'd need both types of "this", so maybe, as with haxe.posInfos,
we could have something like

Public function someFunc() {
        this.x = 9;
        localFunc = function( me : haxe.outerScope ) {
                me.x += 1;
        }
}

Too verbose?  Maybe your way is better after all ;-)

Lee






-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Nicolas Cannasse
Sent: 27 July 2011 20:15
To: The haXe compiler list
Subject: [haXe] this, me and __this__

Hi list,

An important change that I want to make in haXe is to remove the need to
declare a "me" variable in order to access "this" in local functions:

class Foo {
   function bar() {
        var me = this;
        var callb = function() {
                trace(me);
        };
        // ...
   }
}

The idea is that you should be directly able to access "this" (and
this.vars) inside the local function.

However in order to reach that, we need to deal with inconsistencies with
other languages, in particular Javascript.

In JS (and Neko, and Flash), "this" already refer to the "current object",
which is NOT the object in which the local function is declared.

For instance :

class Foo {
   function bar() {
      var me = this;
      var o = { callb : function() trace(untyped this) };
      o.callb();
   }
}

In that case, JS/Neko/Flash behavior would be to have "this == o"
whereas the new haXe behavior would be "this == me"

Currently of course, haXe forbid you to access "this" in local functions,
because of that reason. But, you can still access it with "untyped", which
was used by several haXe std classes implementation in order to access the
"current object this".

So, in order to smooth transition, I have made the following change
(commited in r3864) : 'this' is no longer accessible in local functions,
even in 'untyped' mode. It has to be replaced by '__this__' (still in
'untyped' mode), which will identify the 'current this' and keep actual
behavior. This way we can track all these 'old this' usages and replace them
with '__this__'.

The next step will be to allow 'this' in local functions, this time not only
in untyped mode, but it will automatically create a "var me = this"
variable in the member method outside the local function.

That's it, hope some of you understood what I was talking about :)

Nicolas

--
haXe - an open source web programming language http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: this, me and __this__

laurence taylor
How about some pun on "me, myself & irene"?

Me being the originating context.
Myself or self being the current context.

this *this* or **this** business is most confusing.


On Wed, Jul 27, 2011 at 9:47 PM, Lee Sylvester <[hidden email]> wrote:
Could we not borrow a leaf out of Lua's book?   In Lua (I forget the actual
syntax), but you can do something like this :-

public function someFunc() {
       this.x = 9;
       localFunc = function( this ) {
               this.x += 1;
       }
}

Of course, we'd need both types of "this", so maybe, as with haxe.posInfos,
we could have something like

Public function someFunc() {
       this.x = 9;
       localFunc = function( me : haxe.outerScope ) {
               me.x += 1;
       }
}

Too verbose?  Maybe your way is better after all ;-)

Lee






-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Nicolas Cannasse
Sent: 27 July 2011 20:15
To: The haXe compiler list
Subject: [haXe] this, me and __this__

Hi list,

An important change that I want to make in haXe is to remove the need to
declare a "me" variable in order to access "this" in local functions:

class Foo {
  function bar() {
       var me = this;
       var callb = function() {
               trace(me);
       };
       // ...
  }
}

The idea is that you should be directly able to access "this" (and
this.vars) inside the local function.

However in order to reach that, we need to deal with inconsistencies with
other languages, in particular Javascript.

In JS (and Neko, and Flash), "this" already refer to the "current object",
which is NOT the object in which the local function is declared.

For instance :

class Foo {
  function bar() {
     var me = this;
     var o = { callb : function() trace(untyped this) };
     o.callb();
  }
}

In that case, JS/Neko/Flash behavior would be to have "this == o"
whereas the new haXe behavior would be "this == me"

Currently of course, haXe forbid you to access "this" in local functions,
because of that reason. But, you can still access it with "untyped", which
was used by several haXe std classes implementation in order to access the
"current object this".

So, in order to smooth transition, I have made the following change
(commited in r3864) : 'this' is no longer accessible in local functions,
even in 'untyped' mode. It has to be replaced by '__this__' (still in
'untyped' mode), which will identify the 'current this' and keep actual
behavior. This way we can track all these 'old this' usages and replace them
with '__this__'.

The next step will be to allow 'this' in local functions, this time not only
in untyped mode, but it will automatically create a "var me = this"
variable in the member method outside the local function.

That's it, hope some of you understood what I was talking about :)

Nicolas

--
haXe - an open source web programming language http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: this, me and __this__

Franco Ponticelli
In reply to this post by Lee Sylvester
I don't think it is a good solution because your inline functions will need be to very specific to the context:

var incr: Int;
public function some()
{
  function increment(v : Int) return v + incr; // this must always be specified or is assumed from the local context?
  var arr = Lambda.map([1,2,3], increment);
}

I don't know how to write that with the alternative syntax.

Franco

On Wed, Jul 27, 2011 at 1:47 PM, Lee Sylvester <[hidden email]> wrote:
Could we not borrow a leaf out of Lua's book?   In Lua (I forget the actual
syntax), but you can do something like this :-

public function someFunc() {
       this.x = 9;
       localFunc = function( this ) {
               this.x += 1;
       }
}

Of course, we'd need both types of "this", so maybe, as with haxe.posInfos,
we could have something like

Public function someFunc() {
       this.x = 9;
       localFunc = function( me : haxe.outerScope ) {
               me.x += 1;
       }
}

Too verbose?  Maybe your way is better after all ;-)

Lee






-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Nicolas Cannasse
Sent: 27 July 2011 20:15
To: The haXe compiler list
Subject: [haXe] this, me and __this__

Hi list,

An important change that I want to make in haXe is to remove the need to
declare a "me" variable in order to access "this" in local functions:

class Foo {
  function bar() {
       var me = this;
       var callb = function() {
               trace(me);
       };
       // ...
  }
}

The idea is that you should be directly able to access "this" (and
this.vars) inside the local function.

However in order to reach that, we need to deal with inconsistencies with
other languages, in particular Javascript.

In JS (and Neko, and Flash), "this" already refer to the "current object",
which is NOT the object in which the local function is declared.

For instance :

class Foo {
  function bar() {
     var me = this;
     var o = { callb : function() trace(untyped this) };
     o.callb();
  }
}

In that case, JS/Neko/Flash behavior would be to have "this == o"
whereas the new haXe behavior would be "this == me"

Currently of course, haXe forbid you to access "this" in local functions,
because of that reason. But, you can still access it with "untyped", which
was used by several haXe std classes implementation in order to access the
"current object this".

So, in order to smooth transition, I have made the following change
(commited in r3864) : 'this' is no longer accessible in local functions,
even in 'untyped' mode. It has to be replaced by '__this__' (still in
'untyped' mode), which will identify the 'current this' and keep actual
behavior. This way we can track all these 'old this' usages and replace them
with '__this__'.

The next step will be to allow 'this' in local functions, this time not only
in untyped mode, but it will automatically create a "var me = this"
variable in the member method outside the local function.

That's it, hope some of you understood what I was talking about :)

Nicolas

--
haXe - an open source web programming language http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

RE: this, me and __this__

Lee Sylvester

Well, in a Lua sense, you’d do :-

 

var incr: Int;

public function some()

{

  function increment(v : Int, ?me : haxe.outerScope) return v + me.incr;

  var arr = Lambda.map([1,2,3], increment);

}

 

Lee

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Franco Ponticelli
Sent: 27 July 2011 21:12
To: The haXe compiler list
Subject: Re: [haXe] this, me and __this__

 

I don't think it is a good solution because your inline functions will need be to very specific to the context:

 

var incr: Int;

public function some()

{

  function increment(v : Int) return v + incr; // this must always be specified or is assumed from the local context?

  var arr = Lambda.map([1,2,3], increment);

}

 

I don't know how to write that with the alternative syntax.

 

Franco

 

On Wed, Jul 27, 2011 at 1:47 PM, Lee Sylvester <[hidden email]> wrote:

Could we not borrow a leaf out of Lua's book?   In Lua (I forget the actual
syntax), but you can do something like this :-

public function someFunc() {
       this.x = 9;
       localFunc = function( this ) {
               this.x += 1;
       }
}

Of course, we'd need both types of "this", so maybe, as with haxe.posInfos,
we could have something like

Public function someFunc() {
       this.x = 9;
       localFunc = function( me : haxe.outerScope ) {
               me.x += 1;
       }
}

Too verbose?  Maybe your way is better after all ;-)

Lee






-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Nicolas Cannasse
Sent: 27 July 2011 20:15
To: The haXe compiler list
Subject: [haXe] this, me and __this__


Hi list,

An important change that I want to make in haXe is to remove the need to
declare a "me" variable in order to access "this" in local functions:

class Foo {
  function bar() {
       var me = this;
       var callb = function() {
               trace(me);
       };
       // ...
  }
}

The idea is that you should be directly able to access "this" (and
this.vars) inside the local function.

However in order to reach that, we need to deal with inconsistencies with
other languages, in particular Javascript.

In JS (and Neko, and Flash), "this" already refer to the "current object",
which is NOT the object in which the local function is declared.

For instance :

class Foo {
  function bar() {
     var me = this;
     var o = { callb : function() trace(untyped this) };
     o.callb();
  }
}

In that case, JS/Neko/Flash behavior would be to have "this == o"
whereas the new haXe behavior would be "this == me"

Currently of course, haXe forbid you to access "this" in local functions,
because of that reason. But, you can still access it with "untyped", which
was used by several haXe std classes implementation in order to access the
"current object this".

So, in order to smooth transition, I have made the following change
(commited in r3864) : 'this' is no longer accessible in local functions,
even in 'untyped' mode. It has to be replaced by '__this__' (still in
'untyped' mode), which will identify the 'current this' and keep actual
behavior. This way we can track all these 'old this' usages and replace them
with '__this__'.

The next step will be to allow 'this' in local functions, this time not only
in untyped mode, but it will automatically create a "var me = this"
variable in the member method outside the local function.

That's it, hope some of you understood what I was talking about :)

Nicolas

--
haXe - an open source web programming language http://haxe.org


--
haXe - an open source web programming language
http://haxe.org

 


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: this, me and __this__

laurence taylor
In reply to this post by Franco Ponticelli
I suppose the fallback would be the originating context, with self being the local context. I'm not saying it's a good idea to implement both contexts in haxe, just there should be a well defined difference by which we can talk about them.

On Wed, Jul 27, 2011 at 10:11 PM, Franco Ponticelli <[hidden email]> wrote:
I don't think it is a good solution because your inline functions will need be to very specific to the context:

var incr: Int;
public function some()
{
  function increment(v : Int) return v + incr; // this must always be specified or is assumed from the local context?
  var arr = Lambda.map([1,2,3], increment);
}

I don't know how to write that with the alternative syntax.

Franco

On Wed, Jul 27, 2011 at 1:47 PM, Lee Sylvester <[hidden email]> wrote:
Could we not borrow a leaf out of Lua's book?   In Lua (I forget the actual
syntax), but you can do something like this :-

public function someFunc() {
       this.x = 9;
       localFunc = function( this ) {
               this.x += 1;
       }
}

Of course, we'd need both types of "this", so maybe, as with haxe.posInfos,
we could have something like

Public function someFunc() {
       this.x = 9;
       localFunc = function( me : haxe.outerScope ) {
               me.x += 1;
       }
}

Too verbose?  Maybe your way is better after all ;-)

Lee






-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Nicolas Cannasse
Sent: 27 July 2011 20:15
To: The haXe compiler list
Subject: [haXe] this, me and __this__

Hi list,

An important change that I want to make in haXe is to remove the need to
declare a "me" variable in order to access "this" in local functions:

class Foo {
  function bar() {
       var me = this;
       var callb = function() {
               trace(me);
       };
       // ...
  }
}

The idea is that you should be directly able to access "this" (and
this.vars) inside the local function.

However in order to reach that, we need to deal with inconsistencies with
other languages, in particular Javascript.

In JS (and Neko, and Flash), "this" already refer to the "current object",
which is NOT the object in which the local function is declared.

For instance :

class Foo {
  function bar() {
     var me = this;
     var o = { callb : function() trace(untyped this) };
     o.callb();
  }
}

In that case, JS/Neko/Flash behavior would be to have "this == o"
whereas the new haXe behavior would be "this == me"

Currently of course, haXe forbid you to access "this" in local functions,
because of that reason. But, you can still access it with "untyped", which
was used by several haXe std classes implementation in order to access the
"current object this".

So, in order to smooth transition, I have made the following change
(commited in r3864) : 'this' is no longer accessible in local functions,
even in 'untyped' mode. It has to be replaced by '__this__' (still in
'untyped' mode), which will identify the 'current this' and keep actual
behavior. This way we can track all these 'old this' usages and replace them
with '__this__'.

The next step will be to allow 'this' in local functions, this time not only
in untyped mode, but it will automatically create a "var me = this"
variable in the member method outside the local function.

That's it, hope some of you understood what I was talking about :)

Nicolas

--
haXe - an open source web programming language http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: this, me and __this__

Franco Ponticelli
In reply to this post by Lee Sylvester
Except that you need to change Lambda.map for that to work since it can only take one argument and that is my point ... if you add an argument (even a special one) you will mess with function signatures.

Franco

On Wed, Jul 27, 2011 at 2:18 PM, Lee Sylvester <[hidden email]> wrote:

Well, in a Lua sense, you’d do :-

 

var incr: Int;

public function some()

{

  function increment(v : Int, ?me : haxe.outerScope) return v + me.incr;

  var arr = Lambda.map([1,2,3], increment);

}

 

Lee

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Franco Ponticelli
Sent: 27 July 2011 21:12


To: The haXe compiler list
Subject: Re: [haXe] this, me and __this__

 

I don't think it is a good solution because your inline functions will need be to very specific to the context:

 

var incr: Int;

public function some()

{

  function increment(v : Int) return v + incr; // this must always be specified or is assumed from the local context?

  var arr = Lambda.map([1,2,3], increment);

}

 

I don't know how to write that with the alternative syntax.

 

Franco

 

On Wed, Jul 27, 2011 at 1:47 PM, Lee Sylvester <[hidden email]> wrote:

Could we not borrow a leaf out of Lua's book?   In Lua (I forget the actual
syntax), but you can do something like this :-

public function someFunc() {
       this.x = 9;
       localFunc = function( this ) {
               this.x += 1;
       }
}

Of course, we'd need both types of "this", so maybe, as with haxe.posInfos,
we could have something like

Public function someFunc() {
       this.x = 9;
       localFunc = function( me : haxe.outerScope ) {
               me.x += 1;
       }
}

Too verbose?  Maybe your way is better after all ;-)

Lee






-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Nicolas Cannasse
Sent: 27 July 2011 20:15
To: The haXe compiler list
Subject: [haXe] this, me and __this__


Hi list,

An important change that I want to make in haXe is to remove the need to
declare a "me" variable in order to access "this" in local functions:

class Foo {
  function bar() {
       var me = this;
       var callb = function() {
               trace(me);
       };
       // ...
  }
}

The idea is that you should be directly able to access "this" (and
this.vars) inside the local function.

However in order to reach that, we need to deal with inconsistencies with
other languages, in particular Javascript.

In JS (and Neko, and Flash), "this" already refer to the "current object",
which is NOT the object in which the local function is declared.

For instance :

class Foo {
  function bar() {
     var me = this;
     var o = { callb : function() trace(untyped this) };
     o.callb();
  }
}

In that case, JS/Neko/Flash behavior would be to have "this == o"
whereas the new haXe behavior would be "this == me"

Currently of course, haXe forbid you to access "this" in local functions,
because of that reason. But, you can still access it with "untyped", which
was used by several haXe std classes implementation in order to access the
"current object this".

So, in order to smooth transition, I have made the following change
(commited in r3864) : 'this' is no longer accessible in local functions,
even in 'untyped' mode. It has to be replaced by '__this__' (still in
'untyped' mode), which will identify the 'current this' and keep actual
behavior. This way we can track all these 'old this' usages and replace them
with '__this__'.

The next step will be to allow 'this' in local functions, this time not only
in untyped mode, but it will automatically create a "var me = this"
variable in the member method outside the local function.

That's it, hope some of you understood what I was talking about :)

Nicolas

--
haXe - an open source web programming language http://haxe.org


--
haXe - an open source web programming language
http://haxe.org

 


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: this, me and __this__

laurence taylor
In reply to this post by Lee Sylvester
Sorry, wrong end of the stick. (probably)

On Wed, Jul 27, 2011 at 10:18 PM, Lee Sylvester <[hidden email]> wrote:

Well, in a Lua sense, you’d do :-

 

var incr: Int;

public function some()

{

  function increment(v : Int, ?me : haxe.outerScope) return v + me.incr;

  var arr = Lambda.map([1,2,3], increment);

}

 

Lee

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Franco Ponticelli
Sent: 27 July 2011 21:12


To: The haXe compiler list
Subject: Re: [haXe] this, me and __this__

 

I don't think it is a good solution because your inline functions will need be to very specific to the context:

 

var incr: Int;

public function some()

{

  function increment(v : Int) return v + incr; // this must always be specified or is assumed from the local context?

  var arr = Lambda.map([1,2,3], increment);

}

 

I don't know how to write that with the alternative syntax.

 

Franco

 

On Wed, Jul 27, 2011 at 1:47 PM, Lee Sylvester <[hidden email]> wrote:

Could we not borrow a leaf out of Lua's book?   In Lua (I forget the actual
syntax), but you can do something like this :-

public function someFunc() {
       this.x = 9;
       localFunc = function( this ) {
               this.x += 1;
       }
}

Of course, we'd need both types of "this", so maybe, as with haxe.posInfos,
we could have something like

Public function someFunc() {
       this.x = 9;
       localFunc = function( me : haxe.outerScope ) {
               me.x += 1;
       }
}

Too verbose?  Maybe your way is better after all ;-)

Lee






-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Nicolas Cannasse
Sent: 27 July 2011 20:15
To: The haXe compiler list
Subject: [haXe] this, me and __this__


Hi list,

An important change that I want to make in haXe is to remove the need to
declare a "me" variable in order to access "this" in local functions:

class Foo {
  function bar() {
       var me = this;
       var callb = function() {
               trace(me);
       };
       // ...
  }
}

The idea is that you should be directly able to access "this" (and
this.vars) inside the local function.

However in order to reach that, we need to deal with inconsistencies with
other languages, in particular Javascript.

In JS (and Neko, and Flash), "this" already refer to the "current object",
which is NOT the object in which the local function is declared.

For instance :

class Foo {
  function bar() {
     var me = this;
     var o = { callb : function() trace(untyped this) };
     o.callb();
  }
}

In that case, JS/Neko/Flash behavior would be to have "this == o"
whereas the new haXe behavior would be "this == me"

Currently of course, haXe forbid you to access "this" in local functions,
because of that reason. But, you can still access it with "untyped", which
was used by several haXe std classes implementation in order to access the
"current object this".

So, in order to smooth transition, I have made the following change
(commited in r3864) : 'this' is no longer accessible in local functions,
even in 'untyped' mode. It has to be replaced by '__this__' (still in
'untyped' mode), which will identify the 'current this' and keep actual
behavior. This way we can track all these 'old this' usages and replace them
with '__this__'.

The next step will be to allow 'this' in local functions, this time not only
in untyped mode, but it will automatically create a "var me = this"
variable in the member method outside the local function.

That's it, hope some of you understood what I was talking about :)

Nicolas

--
haXe - an open source web programming language http://haxe.org


--
haXe - an open source web programming language
http://haxe.org

 


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: this, me and __this__

jlm@justinfront.net
In reply to this post by Nicolas Cannasse
There was a small change in the way 'using' worked between versions  
and scopes with these local functions I can't easily detail it as my  
use was probably not usual, but wondered if your considering how class  
statics and using scopes in these local functions and if it will  
change or even be more powerful, not saying how they should just don't  
forget to consider them.

Cheers

;j
On 27 Jul 2011, at 20:15, Nicolas Cannasse wrote:

> Hi list,
>
> An important change that I want to make in haXe is to remove the  
> need to declare a "me" variable in order to access "this" in local  
> functions:
>
> class Foo {
>  function bar() {
> var me = this;
> var callb = function() {
> trace(me);
> };
> // ...
>  }
> }
>
> The idea is that you should be directly able to access "this" (and  
> this.vars) inside the local function.
>
> However in order to reach that, we need to deal with inconsistencies  
> with other languages, in particular Javascript.
>
> In JS (and Neko, and Flash), "this" already refer to the "current  
> object", which is NOT the object in which the local function is  
> declared.
>
> For instance :
>
> class Foo {
>  function bar() {
>     var me = this;
>     var o = { callb : function() trace(untyped this) };
>     o.callb();
>  }
> }
>
> In that case, JS/Neko/Flash behavior would be to have "this == o"  
> whereas the new haXe behavior would be "this == me"
>
> Currently of course, haXe forbid you to access "this" in local  
> functions, because of that reason. But, you can still access it with  
> "untyped", which was used by several haXe std classes implementation  
> in order to access the "current object this".
>
> So, in order to smooth transition, I have made the following change  
> (commited in r3864) : 'this' is no longer accessible in local  
> functions, even in 'untyped' mode. It has to be replaced by  
> '__this__' (still in 'untyped' mode), which will identify the  
> 'current this' and keep actual behavior. This way we can track all  
> these 'old this' usages and replace them with '__this__'.
>
> The next step will be to allow 'this' in local functions, this time  
> not only in untyped mode, but it will automatically create a "var me  
> = this" variable in the member method outside the local function.
>
> That's it, hope some of you understood what I was talking about :)
>
> Nicolas
>
> --
> haXe - an open source web programming language
> http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

RE: this, me and __this__

Lee Sylvester
In reply to this post by Franco Ponticelli

Ahh, good point… Hadn’t considered that :-)

 

Lee

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Franco Ponticelli
Sent: 27 July 2011 21:22
To: The haXe compiler list
Subject: Re: [haXe] this, me and __this__

 

Except that you need to change Lambda.map for that to work since it can only take one argument and that is my point ... if you add an argument (even a special one) you will mess with function signatures.

 

Franco

On Wed, Jul 27, 2011 at 2:18 PM, Lee Sylvester <[hidden email]> wrote:

Well, in a Lua sense, you’d do :-

 

var incr: Int;

public function some()

{

  function increment(v : Int, ?me : haxe.outerScope) return v + me.incr;

  var arr = Lambda.map([1,2,3], increment);

}

 

Lee

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Franco Ponticelli
Sent: 27 July 2011 21:12


To: The haXe compiler list

Subject: Re: [haXe] this, me and __this__

 

I don't think it is a good solution because your inline functions will need be to very specific to the context:

 

var incr: Int;

public function some()

{

  function increment(v : Int) return v + incr; // this must always be specified or is assumed from the local context?

  var arr = Lambda.map([1,2,3], increment);

}

 

I don't know how to write that with the alternative syntax.

 

Franco

 

On Wed, Jul 27, 2011 at 1:47 PM, Lee Sylvester <[hidden email]> wrote:

Could we not borrow a leaf out of Lua's book?   In Lua (I forget the actual
syntax), but you can do something like this :-

public function someFunc() {
       this.x = 9;
       localFunc = function( this ) {
               this.x += 1;
       }
}

Of course, we'd need both types of "this", so maybe, as with haxe.posInfos,
we could have something like

Public function someFunc() {
       this.x = 9;
       localFunc = function( me : haxe.outerScope ) {
               me.x += 1;
       }
}

Too verbose?  Maybe your way is better after all ;-)

Lee






-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Nicolas Cannasse
Sent: 27 July 2011 20:15
To: The haXe compiler list
Subject: [haXe] this, me and __this__


Hi list,

An important change that I want to make in haXe is to remove the need to
declare a "me" variable in order to access "this" in local functions:

class Foo {
  function bar() {
       var me = this;
       var callb = function() {
               trace(me);
       };
       // ...
  }
}

The idea is that you should be directly able to access "this" (and
this.vars) inside the local function.

However in order to reach that, we need to deal with inconsistencies with
other languages, in particular Javascript.

In JS (and Neko, and Flash), "this" already refer to the "current object",
which is NOT the object in which the local function is declared.

For instance :

class Foo {
  function bar() {
     var me = this;
     var o = { callb : function() trace(untyped this) };
     o.callb();
  }
}

In that case, JS/Neko/Flash behavior would be to have "this == o"
whereas the new haXe behavior would be "this == me"

Currently of course, haXe forbid you to access "this" in local functions,
because of that reason. But, you can still access it with "untyped", which
was used by several haXe std classes implementation in order to access the
"current object this".

So, in order to smooth transition, I have made the following change
(commited in r3864) : 'this' is no longer accessible in local functions,
even in 'untyped' mode. It has to be replaced by '__this__' (still in
'untyped' mode), which will identify the 'current this' and keep actual
behavior. This way we can track all these 'old this' usages and replace them
with '__this__'.

The next step will be to allow 'this' in local functions, this time not only
in untyped mode, but it will automatically create a "var me = this"
variable in the member method outside the local function.

That's it, hope some of you understood what I was talking about :)

Nicolas

--
haXe - an open source web programming language http://haxe.org


--
haXe - an open source web programming language
http://haxe.org

 


--
haXe - an open source web programming language
http://haxe.org

 


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: this, me and __this__

Michiel Crefcoeur
So, if I understand this correctly, we can write:

class Example {
  private var x;
  private function example() {
    x=0;
    var plusOne=function() x++;
    plusOne();
  }
}

and when compiled to JS, the example function will look like this?

  function example() {
    this.x=0;
    var __this__=this;
    var plusOne=function() __this__.x++;
    plusOne();
  }

That would be great! :-)
Especially when working with callbacks alot.

2011/7/27 Lee Sylvester <[hidden email]>

Ahh, good point… Hadn’t considered that :-)

 

Lee

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Franco Ponticelli
Sent: 27 July 2011 21:22


To: The haXe compiler list
Subject: Re: [haXe] this, me and __this__

 

Except that you need to change Lambda.map for that to work since it can only take one argument and that is my point ... if you add an argument (even a special one) you will mess with function signatures.

 

Franco

On Wed, Jul 27, 2011 at 2:18 PM, Lee Sylvester <[hidden email]> wrote:

Well, in a Lua sense, you’d do :-

 

var incr: Int;

public function some()

{

  function increment(v : Int, ?me : haxe.outerScope) return v + me.incr;

  var arr = Lambda.map([1,2,3], increment);

}

 

Lee

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Franco Ponticelli
Sent: 27 July 2011 21:12


To: The haXe compiler list

Subject: Re: [haXe] this, me and __this__

 

I don't think it is a good solution because your inline functions will need be to very specific to the context:

 

var incr: Int;

public function some()

{

  function increment(v : Int) return v + incr; // this must always be specified or is assumed from the local context?

  var arr = Lambda.map([1,2,3], increment);

}

 

I don't know how to write that with the alternative syntax.

 

Franco

 

On Wed, Jul 27, 2011 at 1:47 PM, Lee Sylvester <[hidden email]> wrote:

Could we not borrow a leaf out of Lua's book?   In Lua (I forget the actual
syntax), but you can do something like this :-

public function someFunc() {
       this.x = 9;
       localFunc = function( this ) {
               this.x += 1;
       }
}

Of course, we'd need both types of "this", so maybe, as with haxe.posInfos,
we could have something like

Public function someFunc() {
       this.x = 9;
       localFunc = function( me : haxe.outerScope ) {
               me.x += 1;
       }
}

Too verbose?  Maybe your way is better after all ;-)

Lee






-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Nicolas Cannasse
Sent: 27 July 2011 20:15
To: The haXe compiler list
Subject: [haXe] this, me and __this__


Hi list,

An important change that I want to make in haXe is to remove the need to
declare a "me" variable in order to access "this" in local functions:

class Foo {
  function bar() {
       var me = this;
       var callb = function() {
               trace(me);
       };
       // ...
  }
}

The idea is that you should be directly able to access "this" (and
this.vars) inside the local function.

However in order to reach that, we need to deal with inconsistencies with
other languages, in particular Javascript.

In JS (and Neko, and Flash), "this" already refer to the "current object",
which is NOT the object in which the local function is declared.

For instance :

class Foo {
  function bar() {
     var me = this;
     var o = { callb : function() trace(untyped this) };
     o.callb();
  }
}

In that case, JS/Neko/Flash behavior would be to have "this == o"
whereas the new haXe behavior would be "this == me"

Currently of course, haXe forbid you to access "this" in local functions,
because of that reason. But, you can still access it with "untyped", which
was used by several haXe std classes implementation in order to access the
"current object this".

So, in order to smooth transition, I have made the following change
(commited in r3864) : 'this' is no longer accessible in local functions,
even in 'untyped' mode. It has to be replaced by '__this__' (still in
'untyped' mode), which will identify the 'current this' and keep actual
behavior. This way we can track all these 'old this' usages and replace them
with '__this__'.

The next step will be to allow 'this' in local functions, this time not only
in untyped mode, but it will automatically create a "var me = this"
variable in the member method outside the local function.

That's it, hope some of you understood what I was talking about :)

Nicolas

--
haXe - an open source web programming language http://haxe.org


--
haXe - an open source web programming language
http://haxe.org

 


--
haXe - an open source web programming language
http://haxe.org

 


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: this, me and __this__

Michiel Crefcoeur
whoops, in JS, the plusOne function would have braces ofcourse but you get the point ;-)
var plusOne=function() {
  __this__.x++;
};


2011/7/28 Michiel Crefcoeur <[hidden email]>
So, if I understand this correctly, we can write:

class Example {
  private var x;
  private function example() {
    x=0;
    var plusOne=function() x++;
    plusOne();
  }
}

and when compiled to JS, the example function will look like this?

  function example() {
    this.x=0;
    var __this__=this;
    var plusOne=function() __this__.x++;
    plusOne();
  }

That would be great! :-)
Especially when working with callbacks alot.

2011/7/27 Lee Sylvester <[hidden email]>

Ahh, good point… Hadn’t considered that :-)

 

Lee

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Franco Ponticelli
Sent: 27 July 2011 21:22


To: The haXe compiler list
Subject: Re: [haXe] this, me and __this__

 

Except that you need to change Lambda.map for that to work since it can only take one argument and that is my point ... if you add an argument (even a special one) you will mess with function signatures.

 

Franco

On Wed, Jul 27, 2011 at 2:18 PM, Lee Sylvester <[hidden email]> wrote:

Well, in a Lua sense, you’d do :-

 

var incr: Int;

public function some()

{

  function increment(v : Int, ?me : haxe.outerScope) return v + me.incr;

  var arr = Lambda.map([1,2,3], increment);

}

 

Lee

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Franco Ponticelli
Sent: 27 July 2011 21:12


To: The haXe compiler list

Subject: Re: [haXe] this, me and __this__

 

I don't think it is a good solution because your inline functions will need be to very specific to the context:

 

var incr: Int;

public function some()

{

  function increment(v : Int) return v + incr; // this must always be specified or is assumed from the local context?

  var arr = Lambda.map([1,2,3], increment);

}

 

I don't know how to write that with the alternative syntax.

 

Franco

 

On Wed, Jul 27, 2011 at 1:47 PM, Lee Sylvester <[hidden email]> wrote:

Could we not borrow a leaf out of Lua's book?   In Lua (I forget the actual
syntax), but you can do something like this :-

public function someFunc() {
       this.x = 9;
       localFunc = function( this ) {
               this.x += 1;
       }
}

Of course, we'd need both types of "this", so maybe, as with haxe.posInfos,
we could have something like

Public function someFunc() {
       this.x = 9;
       localFunc = function( me : haxe.outerScope ) {
               me.x += 1;
       }
}

Too verbose?  Maybe your way is better after all ;-)

Lee






-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Nicolas Cannasse
Sent: 27 July 2011 20:15
To: The haXe compiler list
Subject: [haXe] this, me and __this__


Hi list,

An important change that I want to make in haXe is to remove the need to
declare a "me" variable in order to access "this" in local functions:

class Foo {
  function bar() {
       var me = this;
       var callb = function() {
               trace(me);
       };
       // ...
  }
}

The idea is that you should be directly able to access "this" (and
this.vars) inside the local function.

However in order to reach that, we need to deal with inconsistencies with
other languages, in particular Javascript.

In JS (and Neko, and Flash), "this" already refer to the "current object",
which is NOT the object in which the local function is declared.

For instance :

class Foo {
  function bar() {
     var me = this;
     var o = { callb : function() trace(untyped this) };
     o.callb();
  }
}

In that case, JS/Neko/Flash behavior would be to have "this == o"
whereas the new haXe behavior would be "this == me"

Currently of course, haXe forbid you to access "this" in local functions,
because of that reason. But, you can still access it with "untyped", which
was used by several haXe std classes implementation in order to access the
"current object this".

So, in order to smooth transition, I have made the following change
(commited in r3864) : 'this' is no longer accessible in local functions,
even in 'untyped' mode. It has to be replaced by '__this__' (still in
'untyped' mode), which will identify the 'current this' and keep actual
behavior. This way we can track all these 'old this' usages and replace them
with '__this__'.

The next step will be to allow 'this' in local functions, this time not only
in untyped mode, but it will automatically create a "var me = this"
variable in the member method outside the local function.

That's it, hope some of you understood what I was talking about :)

Nicolas

--
haXe - an open source web programming language http://haxe.org


--
haXe - an open source web programming language
http://haxe.org

 


--
haXe - an open source web programming language
http://haxe.org

 


--
haXe - an open source web programming language
http://haxe.org



--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: this, me and __this__

Geoffrey Hug
I don't think I get it, what's the right way to access the instance of your class while in a local function ?

class Foo
{
 public function local()
 {
   serverApi.send( this );
 }
}

I basically need to the above and this must represent my instance of Foo.

--
haXe - an open source web programming language
http://haxe.org
12