918Re: [yui3] Inheritance issue
- Sep 25, 2009Hey Greg,
It's actually not Widget related. It narrows down into the following
basic use case:
[ see native console output ]
The object instance created from a class setup in a separate YUI
sandbox instance from the one doing the instanceof check, is the one
Or in farm animal terms...
The animal which doesn't end up on the farm is the one which is
defined outside of the sandbox in which the farm is instantiated.
If you define your Horse class as a module added to YUI, it should work.
I'll follow up a little more on this internally, to understand if this
is a intentional part of sandboxing (since we're keeping one Y.Animal
separate from another) and post back.
On Sep 25, 2009, at 9:01 AM, greg.hinch wrote:
> I'm having some issues creating Widgets and using instanceof, and I
> think the best way I can illustrate it is with an example. I'll
> preface by saying I know the Widget class is still under
> development, but I'd like to know if this pattern I'm trying to
> develop will work but there's just a bug right now, or rather if I'm
> going about my development the wrong way. With that in mind, I've
> created this little sample set of classes that illustrate the
> problem I'm having.
> I'm creating a "farm" component to contain Animals. The Farm
> component has been build as several classes, Farm, Animal, FourLegs,
> and Cat, and built using the YUI Builder to create a single script
> file, and all classes are then added to the Y namespace. Y.Cat
> extends Y.FourLegs, which extends Y.Animal, which extends Y.Widget.
> Y.Farm extends Y.Widget. An animal instance, when rendered, will
> spit out the name of its top-most class, for example Y.Cat will
> display "A cat has been born". A farm is instantiated with a
> property "animals", which is an array of instances of the Y.Animal
> class. When rendered, it will display which animals are in the farm,
> and how many failed to pass the validation. Animals are validated by
> passing an (X instanceof Y.Animal) check. If they fail, they are
> removed from the array and the failed count increases by 1.
> My implementation consists of an inline script, wrapped in YUI.use
> and loading the "farm" component, which declares a new animal type,
> Dog, instantiates one of each animal type and a farm, renders the
> animals, and then the farm. Also on the page I've loaded an external
> script to declare another animal type, a Horse. In that script I've
> called YUI.use, again loading "farm", and created the animal in the
> same way. I then placed that constructor in the my.animals.horse
> global namespace.
> The problem I'm having is that any instance of Horse fails to pass
> the instanceof Y.Animal check in the farm. If I dump out the object
> that's created via Firebug, it appears to be exactly the same type
> of object as Dog and Cat, and it was certainly built the same way,
> but instanceof still fails. Here's the page showing what I just
> Am I just going about this in the wrong way or is this just a bug in
> Widget that will be resolved by the time it goes GA?
- << Previous post in topic Next post in topic >>