Hi,
I have an array of DOM objects and would like to append them all to
one container DIV.
This works fine:
items.each(
function(item) {
container.appendChild(item);
}
);
But this doesn''t:
items.each(container.appendChild);
At least in Firefox I get the following Exception:
[Exception... "Illegal operation on WrappedNative prototype object"
nsresult: "0x8057000c (NS_ERROR_XPC_BAD_OP_ON_WN_PROTO)" location:
"JS
frame :: http://localhost/websites/Latengo/sites/de_DE/web/javascript.php?_ALL_
:: anonymous :: line 572" data: no]
Line 572 is the following line of Enumerable.each:
iterator(value, index++);
Interestingly both versions work in IE without problems.
Can somebody point me in the right direction? I definitely would
prefer using the second method.
Greetings,
Mensler
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
Hmm... some checking: $R(1,5).each(alert) // this works $R(1,5).each(window.alert) // this works $R(1,5).each(document.write) // this doesn''t work Maybe it''s an issue with the document object? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On 8/17/07, Mensler <webplain-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> This works fine: > > items.each( > function(item) { > container.appendChild(item); > } > ); > > But this doesn''t: > > items.each(container.appendChild);I''ve been playing around with this a little, and here''s what I''ve turned up. When you pass container.appendChild, you''re only passing the function appendChild; when it gets inside of each, appendChild is no longer aware of its context in relation to container. Firebug bears this out: stepping through the Prototype code shows that this is pointing to document when it comes time to actually start iterating. The good news is, version 1.6 adds a context argument to each, so now items.each(container.appendChild, container) works ... in Firefox. The bad news is, this doesn''t work in IE6 (I don''t know about 7), and I didn''t feel like poking around with IE. :Dan Dorman --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Dan, interesting investigation :-) So this works in Firefox with earlier versions of Prototype, too: items.each(container.appendChild.bind(container)); As you said, it won''t work in any IE because of the issues I found earlier this day: http://groups.google.com/group/rubyonrails-spinoffs/browse_thread/thread/7e7163b473fd806b Thanks Dave and Dan for your effort. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---