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; }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。