Properties, is this intended?

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

Properties, is this intended?

Michael Cann
class Test 
{
public var a(default, setA) : Int;
public function new() 
{
a = 2;
trace(a); // null??
}
private function setA(value:Int) : Int
{
return value;
}
}

Am I being stupid or shouldn't that trace 2?

This is on the JS target BTW.

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

Re: Properties, is this intended?

rammserker
First, see that this is wrong:

//////////////////////////////////
private function setA(value:Int) : Int
{
return value;
}
//////////////////////////////////

This should be:
/////////////////////////////////
private function setA ( value : Int ) : Int
{
    return a = value;
}
/////////////////////////////////

That will work. In your example you didn't assign any value to "a"

Max
0 1 0 | 0 0 1 | 1 1 1


On Mon, Oct 17, 2011 at 7:33 PM, Michael Cann <[hidden email]> wrote:
class Test 
{
public var a(default, setA) : Int;
public function new() 
{
a = 2;
trace(a); // null??
}
private function setA(value:Int) : Int
{
return value;
}
}

Am I being stupid or shouldn't that trace 2?

This is on the JS target BTW.

--
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: Properties, is this intended?

Andreas Mokros
In reply to this post by Michael Cann
Hi.

On Mon, 17 Oct 2011 22:33:39 +0100
Michael Cann <[hidden email]> wrote:
> private function setA(value:Int) : Int
>  {
> return value;
> }

return a = value; ?

--
Mockey

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

Re: Properties, is this intended?

Michael Cann
In reply to this post by rammserker
Ahh I see! Think ill try to update the wiki with that then:  http://haxe.org/ref/properties

2011/10/17 Maximiliano Fernández <[hidden email]>
First, see that this is wrong:

//////////////////////////////////

private function setA(value:Int) : Int
{
return value;
}
//////////////////////////////////

This should be:
/////////////////////////////////
private function setA ( value : Int ) : Int
{
    return a = value;
}
/////////////////////////////////

That will work. In your example you didn't assign any value to "a"

Max
0 1 0 | 0 0 1 | 1 1 1


On Mon, Oct 17, 2011 at 7:33 PM, Michael Cann <[hidden email]> wrote:
class Test 
{
public var a(default, setA) : Int;
public function new() 
{
a = 2;
trace(a); // null??
}
private function setA(value:Int) : Int
{
return value;
}
}

Am I being stupid or shouldn't that trace 2?

This is on the JS target BTW.

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


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



--
Mike Cann
http://www.mikecann.co.uk/


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