UNPKG

browsernizr

Version:

Modernizr wrapper for use with browserify

42 lines (34 loc) 1.23 kB
var is = require('./is.js'); var fnBind = require('./fnBind.js'); /** * testDOMProps is a generic DOM property test; if a browser supports * a certain property, it won't return undefined for it. * * @access private * @function testDOMProps * @param {Array<string>} props - An array of properties to test for * @param {Object} obj - An object or Element you want to use to test the parameters again * @param {boolean|Object} elem - An Element to bind the property lookup again. Use `false` to prevent the check * @returns {false|*} returns false if the prop is unsupported, otherwise the value that is supported */ function testDOMProps(props, obj, elem) { var item; for (var i in props) { if (props[i] in obj) { // return the property name as a string if (elem === false) { return props[i]; } item = obj[props[i]]; // let's bind a function if (is(item, 'function')) { // bind to obj unless overridden return fnBind(item, elem || obj); } // return the unbound function or obj or value return item; } } return false; } module.exports = testDOMProps;