- Ext JS 3.0 Cookbook
- Jorge Ramon
- 320字
- 2021-04-01 13:43:44
Determining the object type and converting empty references to a default value
This recipe teaches you how to determine the types of different objects using the facilities of Ext JS, as well as a simple method that can be used to initialize empty references with a default value.
How to do it...
You can determine the types of different objects in the following way:
- Create some dummy data structures:
var colorsArray = new Array(); colorsArray[0] = 'Blue'; colorsArray[1] = 'Red'; colorsArray[2] = 'White'; var colorsObject = { color1: 'Blue', color2: 'Red', color3: 'White' }; var aNumber = 1; var aString = '1'; var sample; var empty;
- Check the types of our variables:
var colorsArrayType = Ext.type(colorsArray); // colorsArrayType's value is "array". var isArray = Ext.isArray(colorsArray); // isArray is true var colorsObjectType = Ext.type(colorsObject); // colorsObjectType's value is "object". var isArray = Ext.isArray(colorsObject); // isArray is false var number = Ext.num(aNumber, 0); // number is 1. number = Ext.num(aString, 0); // Since aString is not numeric, the supplied // default value (0) will be returned. var defined = Ext.util.Format.undef(sample); // defined is an empty string sample = "sample is now defined"; defined = Ext.util.Format.undef(sample); // defined is now "sample is now defined". var notEmpty = Ext.value(empty, 'defaultValue', false); // notEmpty is 'defaultValue'
The Ext.type(object)
function is capable of detecting elements, objects, text nodes, whitespaces, functions, arrays, regular expressions, numbers, and node lists.
As its name indicates, Ext.isArray(object)
simply checks whether the passed object is a JavaScript array. Ext.num(value, defaultValue)
, in turn, does a numeric type check on the passed value and returns the default value when the argument is not numeric.
Ext.util.Format.undef(value)
is a very useful function when you need to test for undefined values. It returns either the supplied argument or an empty string if the argument is undefined.
Ext.value(value, defaultValue, allowBlank)
also allows you to specify a default value when the value being tested is undefined.
- 商用級AIGC繪畫創作與技巧(Midjourney+Stable Diffusion)
- Lightroom Classic完全自學一本通
- Illustrator CS6核心應用案例教程(全彩慕課版)
- Flash CC從入門到精通
- 剪映專業版(電腦版)視頻剪輯全攻略:音效添加+轉場特效+視頻制作
- 專業級音樂制作理論與實踐Pro Tools:從入門到應用
- AI繪畫實戰:Midjourney從新手到高手
- AutoCAD 2017從新手到高手
- 量化投資與FOF投資:以MATLAB+Python為工具
- Blender 2.5 Materials and Textures Cookbook
- 正則表達式必知必會(修訂版)
- UG NX 12.0完全自學寶典
- Oracle Warehouse Builder 11g R2: Getting Started 2011
- Origin 2022科學繪圖與數據分析(高級應用篇)
- Oracle E/Business Suite R12 Supply Chain Management