重庆熊猫 Loading

ExtJS类成员-判断数据类型功能

更新记录
2022年7月6日 发布。
2022年7月2日 从笔记迁移到博客。

ExtJS教程汇总:https://www.cnblogs.com/cqpanda/p/16328016.html

获得数据类型

Ext.typeOf ( value ) : String 

返回类型对应关系:

undefined: 			If the given value is undefined
null: 				If the given value is null
string: 			If the given value is a string
number: 			If the given value is a number
boolean: 			If the given value is a boolean value
date: 				If the given value is a Date object
function: 			If the given value is a function reference
object:			 	If the given value is an object
array: 				If the given value is an array
regexp: 			If the given value is a regular expression
element: 			If the given value is a DOM Element
whitespace: 			If the given value is a DOM text node and contains only whitespace
textnode: 			If the given value is a DOM text node
and contains something other than whitespace

判断是否数组类型

Ext.isArray ( target ) : Boolean

实例:

console.log(Ext.isArray([]));//true
console.log(Ext.isArray([0]));//true
console.log(Ext.isArray([1]));//true
console.log(Ext.isArray([""]));//true
console.log(Ext.isArray(['abc']));//true
console.log(Ext.isArray(new Array()));//true
console.log(Ext.isArray(new Array(0)));//true
console.log(Ext.isArray(new Array(1)));//true

判断是否字符串类型

Ext.isString ( value ) : Boolean

实例:

console.log(Ext.isString(''));//true
console.log(Ext.isString(""));//true
console.log(Ext.isString('0'));//true
console.log(Ext.isString(0));//false
console.log(Ext.isString('abc'));//true
console.log(Ext.isString(new String()));//false
console.log(Ext.isString(new String('')));//false

判断是否布尔类型

Ext.isBoolean ( value ) : Boolean

实例:

console.log(Ext.isBoolean(0));//false
console.log(Ext.isBoolean(0.0));//false
console.log(Ext.isBoolean(1));//false
console.log(Ext.isBoolean(true));//true
console.log(Ext.isBoolean(false));//true
console.log(Ext.isBoolean('true'));//false
console.log(Ext.isBoolean('false'));//false
console.log(Ext.isBoolean(new Boolean()));//false

判断是否函数类型

Ext.isFunction ( value ) : Boolean

实例:

console.log(Ext.isFunction(new Function()));//true
console.log(Ext.isFunction(function(){}));//true
console.log(Ext.isFunction(Array.prototype.concat));//true

判断是否日期类型

Ext.isDate ( obj ) : Boolean

实例:

console.log(Ext.isDate('2021-1-11'));//false
console.log(Ext.isDate(new Date()));//true
console.log(Ext.isDate(Date.UTC));//false

判断是否日期(MS) 类型

Ext.isMSDate ( value ) : Boolean

实例:

console.log(Ext.isMSDate('2021-1-11'));//false
console.log(Ext.isMSDate(new Date()));//false
console.log(Ext.isMSDate(Date.UTC));//false

判断是否数值类型

Ext.isNumber ( value ) : Boolean

实例:

console.log(Ext.isNumber(0));//true
console.log(Ext.isNumber(1));//true
console.log(Ext.isNumber('1.1'));//false
console.log(Ext.isNumber(new Number()));//false
console.log(Ext.isNumber((new Number()).valueOf()));//true

判断是否泛数字类型

Ext.isNumeric ( value ) : Boolean

实例:

console.log(Ext.isNumeric(0));//true
console.log(Ext.isNumeric(1));//true
console.log(Ext.isNumeric('1.1'));//true
console.log(Ext.isNumeric(new Number()));//true
console.log(Ext.isNumeric((new Number()).valueOf()));//true

判断是否对象类型

Ext.isObject ( value ) : Boolean

实例:

console.log(Ext.isObject([])); //false
console.log(Ext.isObject({})); //true
console.log(Ext.isObject(new Object())); //true
console.log(Ext.isObject(Ext.create('Ext.button.Button'))); //true
console.log(Ext.isObject(Ext.getWin())); //true

判断是否可迭代类型

Ext.isIterable ( value ) : Boolean

实例:

console.log(Ext.isIterable({}));//false
console.log(Ext.isIterable([])); //true
console.log(Ext.isIterable(Ext.getWin()));//false
console.log(Ext.isIterable(Ext.getBody()));//false

判断是否HTML Element类型

Ext.isElement ( value ) : Boolean

实例:

console.log(Ext.isElement(Ext.getHead()));//false
console.log(Ext.isElement(Ext.getHead().dom));//true
console.log(Ext.isElement(Ext.getBody()));//false
console.log(Ext.isElement(Ext.getBody().dom));//true

判断是否HTML文本节点(TextNode) 类型

Ext.isTextNode ( value ) : Boolean

实例:

console.log(Ext.isTextNode(""));//false
console.log(Ext.isTextNode("Panda"));//false

判断是否标量类型

Ext.isPrimitive ( value ) : Boolean

注意:标量指string/number/boolean类型

实例:

console.log(Ext.isPrimitive(666));//true
console.log(Ext.isPrimitive('Panda'));//true
console.log(Ext.isPrimitive(true));//true
console.log(Ext.isPrimitive([]));//false
console.log(Ext.isPrimitive({}));//false

判断变量是否已经定义

Ext.isDefined ( value ) : Boolean 

实例:

var website = "Panda666.com";
var panda = null;
console.log(Ext.isDefined(panda));//true
console.log(Ext.isDefined([]));//true
console.log(Ext.isDefined(website));//true

判断值是否为空

Ext.isEmpty ( value, [allowEmptyString] ) : Boolean

这些值会判定为空:null、undefined、a zero-length array、a zero-length string(看参数)
实例:

console.log(Ext.isEmpty([]));//true
console.log(Ext.isEmpty(0));//false
console.log(Ext.isEmpty(0.0));//false
console.log(Ext.isEmpty(1));//false
console.log(Ext.isEmpty('0'));//false
console.log(Ext.isEmpty('0.0'));//false
console.log(Ext.isEmpty(null));//true
console.log(Ext.isEmpty(undefined));//true
posted @ 2022-07-06 17:59  重庆熊猫  阅读(261)  评论(0编辑  收藏  举报