Code to Modern Standards. Run Everywhere. poly.js 0.5 is out!

32 views
Skip to first unread message

unscriptable

unread,
Aug 9, 2012, 10:42:07 PM8/9/12
to cuj...@googlegroups.com
In case you haven't heard of poly.js ...

poly.js is a collection of tiny AMD modules that shim (aka "polyfill") old browsers to support modern (aka "ES5-ish") javascript.

So now you can write ES5-ish code like this and expect it to work in IE6:
normalizer = normalize.bind(null, config); // no more var that = this;
output
= Object.keys(obj) // look! iterator functions on objects!
   
.map(function (key) {
        return normalize(obj[key]).trim(); // it's about friggin time you got some trim, huh?
   
})
   
.filter(function (val) {
       
return Date.parse(val); // simplified ISO8601 support (whatevs, man. it werks)
   
});

Shims:
  • Array -- forEach, map, filter, reduce, reduceRight, indexOf, lastIndexOf, isArray, etc.
  • Date -- toISOString, parse (simplified ISO8601)
  • Function -- bind
  • JSON -- JSON2 spec: stringify, parse
  • Object -- create, freeze, keys, seal, defineProperty, etc. (not all of these are fully functional. see README)
  • String -- trim
  • XHR -- full XHR 1.0 API

Size:
  • 4.3KB gzipped, for everything, including full JSON2
  • 3.1KB without JSON2
  • 1.1KB for just the array and function shims (for instance, load whatever you want!)

Fork it!

Use it!  It's easy with curl.js:
curl(
   
// use `preloads` to make sure shims are executed before app modules
   
{ preloads: ['poly/array', 'poly/function', 'poly/xhr'] },
   
['app/main']
);

Or just spread your ES5 love all over the place like this:
curl(
   
// I plan to write me some serious ES5 shiz!
   
{ preloads: ['poly/all'] },
   
['app/main']
);


Reply all
Reply to author
Forward
0 new messages