$A
$A(iterable) -> actualArray
Принимает array-подобную коллекцию (все с числовыми индексами) и возвращает ее виде эквивалентного Array объекта. Этот метод является удобным псевдонимом метода Array.from, и является предпочтительным путем для преобразования переменной в Array.
Основное использование $A() заключается в том, чтобы получить все что угодно в виде массива(например NodeList или HTMLCollection объекты которые возвращают многочисленные методы DOM).
Причина по которой вы захотите получить Array(массив) очень проста: Prototype расширяет Array большим количеством полезных методов, и также смешивает его с модулем Enumerable, который содержит еще много полезных методов.
Таким образом, в Prototype, фактически объект Array является наиболее удобный из всех коллекций, которые вы можете получить.
Преобразование осуществляется достаточно просто: null, undefined и false вернут пустой массив(array); any object featuring an explicit toArray method (as many Prototype objects do) has it invoked; otherwise, we assume the argument "looks like an array" (e.g. features a length property and the [] operator), and iterate over its components in the usual way.
When passed an array, $A makes a copy of that array and returns it.
Examples
The well-known DOM method document.getElementsByTagName() doesn't return an Array, but a NodeList object that implements the basic array "interface." Internet Explorer does not allow us to extend Enumerable onto NodeList.prototype, so instead we cast the returned NodeList to an Array:
var paras = $A(document.getElementsByTagName('p'));
paras.each(Element.hide);
$(paras.last()).show();
Notice we had to use each and Element.hide because $A doesn't perform DOM extensions, since the array could contain anything (not just DOM elements). To use the hide instance method we first must make sure all the target elements are extended:
$A(document.getElementsByTagName('p')).map(Element.extend).invoke('hide');
Want to display your arguments easily? Array features a join method, but the arguments value that exists in all functions does not inherit from Array. So, the tough way, or the easy way?
// The hard way...
function showArgs() {
alert(Array.prototype.join.call(arguments, ', '));
}
// The easy way...
function showArgs() {
alert($A(arguments).join(', '));
}