Hi,

On Aug 26, 5:30 pm, Walter Lee Davis <wa...@wdstudio.com> wrote:
> Rough example:
>
> [1,2,3].each(function(n){ $('someDiv').insert(n + 2); });
>
> will output 345 in your DIV in any browser other than IE.
>
> $A([1,2,3]).each ... etc.
>
> will do it everywhere.

Actually, no. The extensions to arrays, functions, and strings are all
automatic (at the Array.prototype, etc., level) even on IE. It's only
DOM elements that can't be extended prototypically on IE and so have
to be passed through `$` (or Element.extend`) before you use
Prototype's extensions to them.

So this would add a class name on any browser other than IE:

var p = document.createElement('p');
p.addClassName("foo");

...but on IE that would cause the error Lukas is seeing. You have to
do this:

var p = $(document.createElement('p'));
p.addClassName("foo");

...to be compatible with IE (see also below). Prototype has to extend
each element individually, because IE doesn't allow you to extend the
prototype of DOM elements like other browsers do.

Lukas, all element instances you retrieve or create via Prototype
methods will automatically be extended for you, so for instance this
works without an explicit `$`:

var p = new Element('p');
p.addClassName("foo");

...because Prototype's `Element` constructor makes sure the element is
extended before it gives it back to you. It's only when you've gotten
an element reference directly from the DOM that you have to make sure
to pass it through `$`. Note that passing an element through `$` more
than once is a harmless no-op.

Details:
http://www.prototypejs.org/learn/extensions

HTH,
--
T.J. Crowder
Independent Software Engineer
tj / crowder software / com
www / crowder software / com

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to