E
Psevdomassiv is an object whose structure coincides with the structure of the mass (i.e., it stores elements in the indexes from 0 to length-1), but it does not have the methods of completeness due to differences in the prototype.Doing your pseudosics is quite simple:var a = {0 : 'foo', 1: 'bar', length: 2};
Now. a - pseudomassium from two elements. They can be treated in indexes - a[0]♪ a[1] - but he doesn't have methods like that. sort♪ slice♪ concat♪ forEach♪ JSON-serializer also shows it not as a mass, but as an object.In the standard library javascript, the only pseudasy class is Arguments, presented by a special object of arguments in each regular function.Also in the browser javascript, pseudasives are copies of classes NodeList, HTMLCollection and similarities returned by some of the DOM functions, such as document.getElementsByXXX()♪Any function that works with the mass can be applied to pseudassium by calling:a.sort(); // Ошибка: в псевдомассиве нет метода sort
Array.prototype.sort.call(a); // А вот так - работает
[].sort.call(a); // И так тоже работает
Pseudomasics can also be transformed into a normal mass with help. https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Array/slice or https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Array/from :Array.prototype.slice.call(a); // ["foo", "bar"]
Array.from(a); // ["foo", "bar"]