Skip to content

Instantly share code, notes, and snippets.

@koichik
Created November 15, 2010 06:55
Show Gist options
  • Save koichik/700116 to your computer and use it in GitHub Desktop.
Save koichik/700116 to your computer and use it in GitHub Desktop.
ECMAScript 5 compatibility test for Node
// http://kangax.github.com/es5-compat-table/
function test(s, expression) {
var result = expression ? 'Yes' : 'No';
console.log(s + ' : ' + result);
}
test('Object.create', typeof Object.create == 'function');
test('Object.defineProperty', typeof Object.defineProperty == 'function');
test('Object.defineProperties', typeof Object.defineProperties == 'function');
test('Object.getPrototypeOf', typeof Object.getPrototypeOf == 'function');
test('Object.keys', typeof Object.keys == 'function');
test('Object.seal', typeof Object.seal == 'function');
test('Object.freeze', typeof Object.freeze == 'function');
test('Object.preventExtensions', typeof Object.preventExtensions == 'function');
test('Object.isSealed', typeof Object.isSealed == 'function');
test('Object.isFrozen', typeof Object.isFrozen == 'function');
test('Object.isExtensible', typeof Object.isExtensible == 'function');
test('Object.getOwnPropertyDescriptor', typeof Object.getOwnPropertyDescriptor == 'function');
test('Object.getOwnPropertyNames', typeof Object.getOwnPropertyNames == 'function');
test('Date.prototype.toISOString', typeof Date.prototype.toISOString == 'function');
test('Date.now', typeof Date.now == 'function');
test('Array.isArray', typeof Array.isArray == 'function');
test('JSON', typeof JSON == 'object');
test('Function.prototype.bind', typeof Function.prototype.bind == 'function');
test('String.prototype.trim', typeof String.prototype.trim == 'function');
test('Array.prototype.indexOf', typeof Array.prototype.indexOf == 'function');
test('Array.prototype.lastIndexOf', typeof Array.prototype.lastIndexOf == 'function');
test('Array.prototype.every', typeof Array.prototype.every == 'function');
test('Array.prototype.some', typeof Array.prototype.some == 'function');
test('Array.prototype.forEach', typeof Array.prototype.forEach == 'function');
test('Array.prototype.map', typeof Array.prototype.map == 'function');
test('Array.prototype.filter', typeof Array.prototype.filter == 'function');
test('Array.prototype.reduce', typeof Array.prototype.reduce == 'function');
test('Array.prototype.reduceRight', typeof Array.prototype.reduceRight == 'function');
test('Property access on strings', "foobar"[3] === "b");
test('Reserved words as property names', function() {
try {
var obj = { };
eval('obj = ({ if: 1 })');
return obj['if'] === 1;
} catch(err) {
return false;
}
}());
test('Strict mode', (function() {
"use strict";
return !this;
})());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment