ExtJs--15--Ext.is*各種類型判斷的方法,簡單看源碼就可以明白了,extjs判斷瀏覽器

來源:互聯網
上載者:User

ExtJs--15--Ext.is*各種類型判斷的方法,簡單看源碼就可以明白了,extjs判斷瀏覽器

        /**         * Returns true if the passed value is empty, false otherwise. The value is deemed to be empty if it is either:         *         * - `null`         * - `undefined`         * - a zero-length array         * - a zero-length string (Unless the `allowEmptyString` parameter is set to `true`)         *         * @param {Object} value The value to test         * @param {Boolean} allowEmptyString (optional) true to allow empty strings (defaults to false)         * @return {Boolean}         * @markdown         */        isEmpty: function(value, allowEmptyString) {            return (value === null) || (value === undefined) || (!allowEmptyString ? value === '' : false) || (Ext.isArray(value) && value.length === 0);        },        /**         * Returns true if the passed value is a JavaScript Array, false otherwise.         *         * @param {Object} target The target to test         * @return {Boolean}         * @method         */        isArray: ('isArray' in Array) ? Array.isArray : function(value) {            return toString.call(value) === '[object Array]';        },        /**         * Returns true if the passed value is a JavaScript Date object, false otherwise.         * @param {Object} object The object to test         * @return {Boolean}         */        isDate: function(value) {            return toString.call(value) === '[object Date]';        },        /**         * Returns true if the passed value is a JavaScript Object, false otherwise.         * @param {Object} value The value to test         * @return {Boolean}         * @method         */        isObject: (toString.call(null) === '[object Object]') ?        function(value) {            // check ownerDocument here as well to exclude DOM nodes            return value !== null && value !== undefined && toString.call(value) === '[object Object]' && value.ownerDocument === undefined;        } :        function(value) {            return toString.call(value) === '[object Object]';        },        /**         * @private         */        isSimpleObject: function(value) {            return value instanceof Object && value.constructor === Object;        },        /**         * Returns true if the passed value is a JavaScript 'primitive', a string, number or boolean.         * @param {Object} value The value to test         * @return {Boolean}         */        isPrimitive: function(value) {            var type = typeof value;            return type === 'string' || type === 'number' || type === 'boolean';        },        /**         * Returns true if the passed value is a JavaScript Function, false otherwise.         * @param {Object} value The value to test         * @return {Boolean}         * @method         */        isFunction:        // Safari 3.x and 4.x returns 'function' for typeof <NodeList>, hence we need to fall back to using        // Object.prototype.toString (slower)        (typeof document !== 'undefined' && typeof document.getElementsByTagName('body') === 'function') ? function(value) {            return toString.call(value) === '[object Function]';        } : function(value) {            return typeof value === 'function';        },        /**         * Returns true if the passed value is a number. Returns false for non-finite numbers.         * @param {Object} value The value to test         * @return {Boolean}         */        isNumber: function(value) {            return typeof value === 'number' && isFinite(value);        },        /**         * Validates that a value is numeric.         * @param {Object} value Examples: 1, '1', '2.34'         * @return {Boolean} True if numeric, false otherwise         */        isNumeric: function(value) {            return !isNaN(parseFloat(value)) && isFinite(value);        },        /**         * Returns true if the passed value is a string.         * @param {Object} value The value to test         * @return {Boolean}         */        isString: function(value) {            return typeof value === 'string';        },        /**         * Returns true if the passed value is a boolean.         *         * @param {Object} value The value to test         * @return {Boolean}         */        isBoolean: function(value) {            return typeof value === 'boolean';        },        /**         * Returns true if the passed value is an HTMLElement         * @param {Object} value The value to test         * @return {Boolean}         */        isElement: function(value) {            return value ? value.nodeType === 1 : false;        },        /**         * Returns true if the passed value is a TextNode         * @param {Object} value The value to test         * @return {Boolean}         */        isTextNode: function(value) {            return value ? value.nodeName === "#text" : false;        },        /**         * Returns true if the passed value is defined.         * @param {Object} value The value to test         * @return {Boolean}         */        isDefined: function(value) {            return typeof value !== 'undefined';        },        /**         * Returns true if the passed value is iterable, false otherwise         * @param {Object} value The value to test         * @return {Boolean}         */        isIterable: function(value) {            var type = typeof value,                checkLength = false;            if (value && type != 'string') {                // Functions have a length property, so we need to filter them out                if (type == 'function') {                    // In Safari, NodeList/HTMLCollection both return "function" when using typeof, so we need                    // to explicitly check them here.                    if (Ext.isSafari) {                        checkLength = value instanceof NodeList || value instanceof HTMLCollection;                    }                } else {                    checkLength = true;                }            }            return checkLength ? value.length !== undefined : false;        }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.