• ExtJs--15--Ext.is*各种类型推断的方法,简单看源代码就能够明确了


            /**
             * 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;
            }

  • 相关阅读:
    switch循环所支持的数据类型
    java里面main方法中的String[]args
    java基本数据类型
    Jquery自定义插件
    Jquery插件(常用的插件库)
    【JAVA SE基础篇】43.Map接口和Set接口的常用方法
    【JAVA SE基础篇】42.手工实现ArrayList和LinkedList
    【JAVA SE基础篇】41.Collection、List方法和ArrayList、LinkedList、Vector底层实现
    【JAVA SE基础篇】40.容器(集合)和泛型的介绍
    【JAVA SE基础篇】39.编译时异常
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/4296435.html
Copyright © 2020-2023  润新知