COMPATIBILITY

Copyright(c) 2013 Stefano Balietti MIT Licensed

Tests browsers ECMAScript 5 compatibility

(function(JSUS) {

    function COMPATIBILITY() {};

COMPATIBILITY.compatibility

Returns a report of the ECS5 features available

Useful when an application routinely performs an operation depending on a potentially unsupported ECS5 feature.

Transforms multiple try-catch statements in a if-else

Returns
object support The compatibility object
    COMPATIBILITY.compatibility = function() {

        var support = {};

        try {
            Object.defineProperty({}, "a", {enumerable: false, value: 1})
            support.defineProperty = true;
        }
        catch(e) {
            support.defineProperty = false;
        }

        try {
            eval('({ get x(){ return 1 } }).x === 1')
            support.setter = true;
        }
        catch(err) {
            support.setter = false;
        }

        try {
            var value;
            eval('({ set x(v){ value = v; } }).x = 1');
            support.getter = true;
        }
        catch(err) {
            support.getter = false;
        }

        return support;
    };


    JSUS.extend(COMPATIBILITY);

})('undefined' !== typeof JSUS ? JSUS : module.parent.exports.JSUS);