[Proto-Scripty] Re: examine whether methode is already used

2009-04-02 Thread T.J. Crowder

Hi,

 Prototype's api docs (http://www.prototypejs.org/api/element/
 getElementsByClassName) state that the method returns an array,
 normally.

They also say As of Prototype 1.6, document.getElementsByClassName
has been deprecated since native implementations return a NodeList
rather than an Array. Please use $$ or Element#select instead.

 When two methods with the same name are available, one in prototype
 and one from the browser, am I able to determine which method is used?

That would probably be tricky, but basically, you shouldn't have to.
The Core team (now) try to avoid choosing signatures that will be
similar-but-different in a future native implementation (where
possible, obviously!) and as with getElementsByClassName will
typically obsolete (deprecate) where that hasn't been possible,
documenting the replacement.

HTH,
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available

On Apr 2, 8:57 am, basti bastian.friedr...@am-soft.de wrote:
 Good morning,

 I wanted to use the method getElementsByClassName by prototype to
 retrieve an array of objects. Using my Firefox 3.0.7 on Windows XP
 alert told me that the returned value by this method is a Nodelist,
 which I couldn't iterate using prototypes each-method for arrays.

 Prototype's api docs (http://www.prototypejs.org/api/element/
 getElementsByClassName) state that the method returns an array,
 normally. Using google I found this 
 link:https://developer.mozilla.org/en/DOM/document.getElementsByClassName
 It seems that getElementsByClassName is implemented by Firefox and
 prototyp and that prototype doesn't override the native
 implementation.

 When two methods with the same name are available, one in prototype
 and one from the browser, am I able to determine which method is used?
 I understand that prototype doesn't want to override native
 implementations of methods to not break browser compability but in
 this case where I use prototype to achieve that my scripts run the
 same way on almost every browser Firefox's impolementation of the
 prototype function is breaking my script because of incompatible
 returned data types by the two implementations of the method.

 I couldn't find any suggestions on how to deal with those situations.
 Is the only way to check for the needed data types on method returns
 and work around the fact that methods may be implemented in the
 browser nativley using different data types for return values? This
 would be a lot of work to do for every common function provided by
 prototype which could be implemented natively, too.

 bye
 basti
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: examine whether methode is already used

2009-04-02 Thread disccomp

$$('.ClassNameToGet')
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: examine whether methode is already used

2009-04-02 Thread RobG



On Apr 2, 5:57 pm, basti bastian.friedr...@am-soft.de wrote:
 Good morning,

 I wanted to use the method getElementsByClassName by prototype to
 retrieve an array of objects. Using my Firefox 3.0.7 on Windows XP
 alert told me that the returned value by this method is a Nodelist,
 which I couldn't iterate using prototypes each-method for arrays.

You can convert the retuned NodeList to an array using $A(), or if you
want to be a little clever you can test the returned object's
constructor and only convert non-Arrays:

  var nodes = document.getElementsByClassName('foo');
  if (nodes.constructor != Array) {
nodes = $A(nodes);
  }

The host getElementsByClassName is likely much faster in general than
a native javascript replacement.

HTML 5 includes a selector API that will provide host methods for a
much greater range of selectors, they should offer significant speed
enhancements over current native selector APIs.

URL: http://www.w3.org/TR/selectors-api/ 

--
Rob
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---