On 2/19/07, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
>
> Hi everyone,
>
> I have been using mochikit for a while with a lot of success (after
> the initial frustrations of getting to grips with the weirdness of
> javascript ;-), but today ran into a problem in Safari with the
> function createDOM. Here is what it boils down to
>
>
> <div id="mydiv">blah</div>
>
> <script type="text/javascript">
> mydiv = $(mydiv);
> createDOM("div", {}, mydiv.childNodes);
> </script>
>
> fails in Safari with the following error
> TypeError - Value undefined (result of expression node.apply) is not
> object.
> http://localhost/mochikit/MochiKit/DOM.js Line:323
>
> Looking at that file it appears that the function coerceToDOM sees
> mydiv.childNodes as a function rather than an array of nodes, hence
> tries to apply this function without much success...
>
> Indeed if I check typeof(mydiv.childNodes) I get "function".
>
> My fix has been to change
> mydiv.childNodes
> to
> map(null, mydiv.childNodes)
> in order to coerce it into an iterable object. This works.
>
> I have then two questions:
> 1. Was my expectation that the little script above should work
> unfounded ? If so, why ?
If it did work, then it would probably move all of the child nodes
from one div to the other.
> 2. Is there a better way to go around this problem ? Maybe the
> coerceToDOM function should check for the existence of node.apply
> before using it ?
Safari will crash if you try and do that unfortunately. That might be
able to be special cased by checking to see if they're an instance of
something.
It look like you might just want to do mydiv.cloneNode(true).
-bob
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"MochiKit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---