flex-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Josh Tynjala (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (FLEX-34913) Types passed by reference should not be stored on the prototype because they are shared by all instances
Date Tue, 21 Jul 2015 23:34:05 GMT

     [ https://issues.apache.org/jira/browse/FLEX-34913?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Josh Tynjala updated FLEX-34913:
--------------------------------
    Description: 
Try the following ActionScript:

class Example
{
    public var prop:Object = {};
}

var obj:Example = new Example();
obj.prop["value"] = 5;

var obj2:Example = new Example();
trace(obj2.prop["value"]); //5

The emitter puts the prop member on the prototype, so it is shared by all instances of Example:

Example.prototype.prop = {};

Instead, the emitter should set the property in Example's constructor so that each instance
has a separate object.

There is a workaround. A developer can manually set the property in the constructor:

class Example
{
	public function Example()
	{
		this.prop = {};
	}

	public var prop:Object;
}

  was:
Try the following ActionScript:

class Example
{
    public var prop:Object = {};
}

var obj:Example = new Example();
obj.prop["value"] = 5;

var obj2:Example = new Example();
trace(obj2.prop["value"]); //5

The emitter puts the prop member on the prototype, so it is shared by all instances of Example:

Example.prototype.prop = {};

Instead, prop should be set in Example's constructor so that each instance has a separate
object.


> Types passed by reference should not be stored on the prototype because they are shared
by all instances
> --------------------------------------------------------------------------------------------------------
>
>                 Key: FLEX-34913
>                 URL: https://issues.apache.org/jira/browse/FLEX-34913
>             Project: Apache Flex
>          Issue Type: Bug
>          Components: FalconJX
>    Affects Versions: Apache FalconJX 0.0.3
>            Reporter: Josh Tynjala
>
> Try the following ActionScript:
> class Example
> {
>     public var prop:Object = {};
> }
> var obj:Example = new Example();
> obj.prop["value"] = 5;
> var obj2:Example = new Example();
> trace(obj2.prop["value"]); //5
> The emitter puts the prop member on the prototype, so it is shared by all instances of
Example:
> Example.prototype.prop = {};
> Instead, the emitter should set the property in Example's constructor so that each instance
has a separate object.
> There is a workaround. A developer can manually set the property in the constructor:
> class Example
> {
> 	public function Example()
> 	{
> 		this.prop = {};
> 	}
> 	public var prop:Object;
> }



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message