Skip to content
February 15, 2012 / zlost

Fast native methods for javascript collections

I’ve been really lucky lately because any javascript I write on the job need only work on WebKit browsers. This has allowed me to use some of the newer native methods defined for collections.

Here’s a gist demonstrating the most useful ones.

If you are one of the poor souls still supports IE or whatever, the excellent underscore.js library wraps these native methods in such a way that calling a wrapper method in an interpreter that implements the native method delegates the work to the native version, and falls back to underscore’s javascript implementation otherwise.

Since underscore.js uses native collection methods when available, its each and map methods are preferable to jQuery’s, which are implemented as straightforward javascript for loops regardless of the availability of native implementations in all modern browsers.

Node users can directly invoke the native methods with impunity, as Node is built on the excellent V8 VM which natively supports all of the aforementioned methods.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: