flex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Harui <aha...@adobe.com>
Subject Re: [FlexJS] value.hasOwnProperty not working, maybe a bug
Date Tue, 10 Jan 2017 17:33:54 GMT
Hi Josh,

Thanks for looking into it.  If you have more time, do you get different
responses in Flash if the class is dynamic or if you use prototype
inheritance in Flash?  IIRC, AS3 classes do not use prototype inheritance,
it is something different.

I'm not sure if we should override hasOwnProperty to behave like SWF or
just warn folks not to use it or something else.  Isn't the semantic use
of hasOwnProperty to determine if anyone has set the property?  I think
even in JS, setting the property may not change what hasOwnProperty
returns since the setter will fire and change the backing variable.

Thoughts?
-Alex

On 1/10/17, 8:48 AM, "Josh Tynjala" <joshtynjala@gmail.com> wrote:

>Here's what I found. If a property is getter, hasOwnProperty() behaves
>differently in Flash and JS.
>
>class ExampleClass
>{
>    public function get prop():String
>    {
>        return "test";
>    }
>}
>
>var test:ExampleClass = new ExampleClass();
>console.log(test.hasOwnProperty("prop"); //true in Flash, false in JS
>console.log("prop" in test) //true in both
>
>However, as you can see, the "in" keyword will behave the same in both.
>
>I also discovered that hasOwnProperty() behaves differently in Flash and
>JS, if the property is defined on a superclass.
>
>class ExampleSuperClass
>{
>    public var superProp:String = "test2";
>}
>
>class ExampleClass extends ExampleSuperClass
>{
>}
>
>var test:ExampleClass = new ExampleClass();
>console.log(test.hasOwnProperty("superProp"); //true in Flash, false in JS
>console.log("superProp" in test) //true in both
>
>Again, the "in" keyword to the rescue.
>
>According to MDN, hasOwnProperty() does not walk up the prototype chain in
>JS, but the "in" keyword does. Apparently, they both walk up the
>inheritance chain in Flash.
>
>- Josh
>
>On Sat, Jan 7, 2017 at 1:36 PM, Alex Harui <aharui@adobe.com> wrote:
>
>> What is a test case where Hasownproperty behaves differently between js
>> and as?
>>
>> Sent from my LG G3, an AT&T 4G LTE smartphone
>>
>> ------ Original message------
>> *From: *Josh Tynjala
>> *Date: *Sat, Jan 7, 2017 11:12 AM
>> *To: *dev@flex.apache.org;
>> *Subject:*Re: [FlexJS] value.hasOwnProperty not working, maybe a bug
>>
>> I don't recall it being discouraged. I use it somewhat frequently with
>>the
>> Flash runtimes. Never had a situation where it failed on me.
>>
>> - Josh
>>
>> On Jan 7, 2017 9:42 AM, "Alex Harui" <aharui@adobe.com> wrote:
>>
>> > Also properties are made via object.de<http://object.de>fineproperty.
>> > that may affect hasownproperty.  I don't think there is a way around
>> that.
>> > Hasownproperty was discouraged in ActionScript for similar reasons,
>>Iirc.
>> >
>> > Sent from my LG G3, an AT&T 4G LTE smartphone
>> >
>> > ------ Original message------
>> > From: Carlos Rovira
>> > Date: Sat, Jan 7, 2017 9:21 AM
>> > To: dev@flex.apache.org;
>> > Subject:Re: [FlexJS] value.hasOwnProperty not working, maybe a bug
>> >
>> > Hi Josh,
>> >
>> > many thanks, your workaround works, but it's a shame that
>> "hasOwnProperty"
>> > can't be used and does not be reliable :(
>> >
>> > Thanks!
>> >
>> > :)
>> >
>> >
>> >
>> > 2017-01-07 17:28 GMT+01:00 Josh Tynjala <joshtynjala@gmail.com>:
>> >
>> > > Are you testing a release build? Remember that Closure compiler
>>renames
>> > > member variables, so using a string to check if they exist won't
>>work.
>> > >
>> > > It can be frustrating, I know. To this day, I still wish that this
>> > drastic
>> > > renaming with Closure hadn't been the default we chose. It breaks a
>> > number
>> > > of common things like this.
>> > >
>> > > You may be able to do something like this instead, I think:
>> > >
>> > > If(value.label !== undefined)
>> > >
>> > > JavaScript generally won't throw an error when you try to access a
>> > property
>> > > that doesn't exist because all JS objects are dynamic by default.
>> > >
>> > > - Josh
>> > >
>> > > On Jan 7, 2017 5:02 AM, "Carlos Rovira" <carlosrovira@apache.org>
>> wrote:
>> > >
>> > > > Hi,
>> > > >
>> > > > I have this code in a Item Renderer:
>> > > >
>> > > > override public function set data(value:Object):void
>> > > > {
>> > > > super.data = value;
>> > > >
>> > > > if(value == null) return;
>> > > >
>> > > > /*if(value.hasOwnProperty('label')) {
>> > > >                 label = String(value.label);
>> > > > } else {
>> > > > label = String(value);
>> > > > }*/
>> > > > label = String(value.label);
>> > > >
>> > > >             /*if(value.hasOwnProperty('href')) {
>> > > >                 href = String(value.href);
>> > > > }*/
>> > > >             href = String(value.href);
>> > > >
>> > > > COMPILE::JS
>> > > > {
>> > > > if(textNode != null)
>> > > > {
>> > > > textNode.nodeValue = label;
>> > > > }
>> > > > }
>> > > > }
>> > > >
>> > > > The commented code is not working. So I committed the line just
>>below
>> > to
>> > > > get it working for now.
>> > > >
>> > > > I'm passing typed object in the dataProvider :
>> > > >
>> > > > package vos
>> > > > {
>> > > >     public class NavigationLinkVO
>> > > >     {
>> > > >         [Bindable]
>> > > >         public var label:String;
>> > > >         [Bindable]
>> > > >         public var href:String;
>> > > >
>> > > >         public function NavigationLinkVO(label:String,
>>href:String)
>> > > >         {
>> > > >             this.label = label;
>> > > >             this.href = href;
>> > > >         }
>> > > >     }
>> > > > }
>> > > >
>> > > > And the dataProvider is:
>> > > >
>> > > > private var _mainNavigation:Array = [
>> > > >                 new NavigationLinkVO("About", "
>> > > > https://getmdl.io/index.html
>> > > > "),
>> > > >                 new NavigationLinkVO("Getting Started", "
>> > > > https://getmdl.io/started/index.html"),
>> > > >                 new NavigationLinkVO("Components", "
>> > > > https://getmdl.io/components/index.html"),
>> > > >                 new NavigationLinkVO("Customize", "
>> > > > https://getmdl.io/customize/index.html")
>> > > >         ];
>> > > >
>> > > > So, "label" and "href" are properties in the object, so why
>> > > > "hasOwnProperty" is not working? is a bug?
>> > > >
>> > > > Thanks
>> > > >
>> > > > --
>> > > > Carlos Rovira
>> > > > http://about.me/carlosrovira
>> > > >
>> > >
>> >
>> >
>> >
>> > --
>> >
>> > Carlos Rovira
>> > Director General
>> > M: +34 607 22 60 05
>> > http://www.codeoscopic.com
>> > http://www.avant2.es
>> >
>> > Este mensaje se dirige exclusivamente a su destinatario y puede
>>contener
>> > información privilegiada o confidencial. Si ha recibido este mensaje
>>por
>> > error, le rogamos que nos lo comunique inmediatamente por esta misma
>>vía
>> y
>> > proceda a su destrucción.
>> >
>> > De la vigente Ley Orgánica de Protección de Datos (15/1999), le
>> comunicamos
>> > que sus datos forman parte de un fichero cuyo responsable es
>>CODEOSCOPIC
>> > S.A. La finalidad de dicho tratamiento es facilitar la prestación del
>> > servicio o información solicitados, teniendo usted derecho de acceso,
>> > rectificación, cancelación y oposición de sus datos dirigiéndose a
>> nuestras
>> > oficinas c/ Paseo de la Habana 9-11, 28036, Madrid con la
>>documentación
>> > necesaria.
>> >
>>

Mime
View raw message