#151 ✓not_for_core

parent.subclasses is undefined (was: Extending YUI objects with prototype)

Reported by Webbles | June 6th, 2008 @ 06:13 PM

We use both YUI and prototype and have classes built using both libraries. When I take YUI class and subclass it with a prototype class, I get a javascript error saying that parent.subclasses is undefined. That is because YUI doesn't add the subclasses array to its objects while prototype does and expects it to be there.

I've modified the prototype source code to have a check for subclasses and if not defined, define it to an empty array. It would be nice if this was in the main source code so I wouldn't have to keep modifying prototype on each release.

Comments and changes to this ticket

  • Juriy Zaytsev

    Juriy Zaytsev June 6th, 2008 @ 06:40 PM

    And what is stopping you from creating parent classes via Prototype?

  • John-David Dalton

    John-David Dalton June 7th, 2008 @ 03:36 AM

    Could you please attach a patch to this ticket :)

    I don't know about this bug. I would like to hear what the core devs think.

    I can see this being "not for core".

  • Webbles

    Webbles June 7th, 2008 @ 05:47 AM

    Here's a diff.

    As for Juriy's question, nothing is stopping us. We have parent classes that are prototype based as well as parent classes that are YUI based. But when we try and extend a YUI class using the Prototype Class.create() method, we have to have this change. This is because YUI doesn't add the subclasses array to the objects and Prototype expects the parent object to have it.

    I'm not sure how I'd go about fixing this without modifying the code. I guess I could wrap the Class.create() function and do the check for the subclasses array in the wrapping function. I haven't tried that so I don't know if it will work.

  • Juriy Zaytsev

    Juriy Zaytsev June 7th, 2008 @ 06:13 AM

    Hmm, could you try if this works?

    Class.create = Class.create.wrap(function(proceed, parent) {
      if (Object.isFunction(parent))
        parent.subclasses = parent.subclasses || [];
      return proceed.apply(Class, $A(arguments).slice(1));
  • Webbles

    Webbles June 9th, 2008 @ 07:05 PM

    That code worked great.

  • Andrew Dupont

    Andrew Dupont June 9th, 2008 @ 09:42 PM

    • State changed from “new” to “not_for_core”
  • Nightfly

    Nightfly February 2nd, 2009 @ 10:31 PM

    • Title changed from “Extending YUI objects with prototype” to “parent.subclasses is undefined (was: Extending YUI objects with prototype)”
  • jeuxnewbanat

    jeuxnewbanat March 18th, 2016 @ 02:13 AM

    • Importance changed from “” to “”

    شكرا لك اخي اتمنى لك حظ موفق وفي اقرب وقت تجد الحل الخاص بك + وجدت مؤخرا موقع al3ab banat جميل جدا يا ترى لااعلم من صاحب هدا الموقع

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Prototype JavaScript library.

Shared Ticket Bins


Referenced by