This project is archived and is in readonly mode.

#551 ✓invalid
Kenton

Can no longer bypass intialize method in 1.2.1

Reported by Kenton | January 13th, 2009 @ 12:00 AM | in 2.0 (closed)

Since 1.0 (and possibly longer) it has been possible to bypass the constructor using the following syntax

new MyObject($empty);

It looks like 1.2.1 (and trunk) this is no longer possible. I see that using the Class.prototyping I can somehow do this but it seems a little too internal for me.

Here is the relevant code differences: http://mootools.pastebin.com/m19...

I suggest simply adding this line below the Class.prototyping (line 20 on trunk)

if (arguments.length > 0 && arguments[0] === $empty) return this;

This has resolved the issue for me. Please let me know if there is a better way to handle this.

Comments and changes to this ticket

  • Valerio

    Valerio January 13th, 2009 @ 01:01 AM

    True, this is not possible any longer.

    If you dont mind me asking, why do you need the functionality? We removed it since it was internal, and nobody really needed such thing anyways.

  • Kenton

    Kenton January 13th, 2009 @ 06:06 PM

    Valerio, sure the reason I use this is I have a base class I use throughout my projects called ElementExtension. As you might guess this is a standardized binding of a class instance to an Element (and has features such as integration with garbage collection).

    There are two ways to use an element extension, one is just create a new class for example

    var queue = new Queue(arg1, {options}); $('holder').adopt(queue.getElement());

    or alternatively

    $('holder').setExtension(Queue, arg1, {options});

    setExtension is an extension of element and does the following http://mootools.pastebin.com/d75...

    As you can see we actually set the element and then run initialize. This way each subclass of ElementExtension doesn't have to have an element argument passed into it and therefore doesn't have to be aware of which method it is being called by.

    I would love to have this feature re-enabled so I don't have to have have a modified core. I don't see anyway to do what I'd like to do without this feature.

    Thanks!

  • Jan Kassens

    Jan Kassens November 22nd, 2009 @ 12:18 PM

    • Assigned user changed from “Valerio” to “Jan Kassens”
    • State changed from “new” to “invalid”

    You should use the Factory pattern for this or something (I'm sure there's a 'proper' OO solution to this issue).

    Skipping initialization was really just there because of the way inheritance was implemented.

Create your profile

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

Shared Ticket Bins

Pages