gordonbrander / array-generics

Polyfill for Array Generic functions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Array Generics Polyfill

A quick and simple polyfill for Array generic functions.

Array generics allow you to work with any array-like object. For example, how many times have you had to do something like this?

function myFunction() {
  var rest = Array.prototype.slice.call(arguments, 1);
}

Lame-o

The bummer about methods is that they can only work with one type.

How about this instead?

function myFunction() {
  var rest = Array.slice(arguments, 1);
}

Not bad

What about this?

var specialEl = $('#special-el');
var els = $('.foo');

var specialElIndex = Array.indexOf(els, specialEl);

Nice!

Or this?

var isAllGood = Array.every($('li'), function (el) {
  return el.hasClass('good');
});

Sweet!

Basically, Array Generics let you do array stuff with less fuss. Hack on!

About

Polyfill for Array Generic functions

License:MIT License


Languages

Language:JavaScript 100.0%